Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Pr0methean committed Jun 25, 2023
1 parent 6a9deff commit 63c2780
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions rayon-core/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,12 @@ struct ThreadInfo {

/// the "stealer" half of the worker's deque
stealer: Stealer<JobRef>,

/// True if a job that has yielded is on the stack. Since yielding
/// results in both the yielding job and another job having stack
/// frames, we prevent the second job from also yielding to prevent
/// a stack overflow.
is_yielding: bool,
}

impl ThreadInfo {
Expand All @@ -653,6 +659,7 @@ impl ThreadInfo {
stopped: LockLatch::new(),
terminate: OnceLatch::new(),
stealer,
is_yielding: false,
}
}
}
Expand Down Expand Up @@ -857,19 +864,31 @@ impl WorkerThread {
}

pub(super) fn yield_now(&self) -> Yield {
let yielding = &mut self.registry.thread_infos[self.index].is_yielding;
if *yielding {
return Yield::Recursive;
}
match self.find_work() {
Some(job) => unsafe {
*yielding = true;
self.execute(job);
*yielding = false;
Yield::Executed
},
None => Yield::Idle,
}
}

pub(super) fn yield_local(&self) -> Yield {
let yielding = &mut self.registry.thread_infos[self.index].is_yielding;
if *yielding {
return Yield::Recursive;
}
match self.take_local_job() {
Some(job) => unsafe {
*yielding = true;
self.execute(job);
*yielding = false;
Yield::Executed
},
None => Yield::Idle,
Expand Down
2 changes: 2 additions & 0 deletions rayon-core/src/thread_pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,6 @@ pub enum Yield {
Executed,
/// No available work was found.
Idle,
/// Another job that has yielded is already on the stack.
Recursive,
}

0 comments on commit 63c2780

Please sign in to comment.