Skip to content

Commit

Permalink
join: Only continue if joinee finished
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening committed Jun 20, 2023
1 parent 2350c5b commit 51ef3d0
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,22 +757,20 @@ pub fn join(id: TaskId) -> Result<(), ()> {
id
);

{
match WAITING_TASKS.lock().get_mut(&id) {
Some(queue) => {
queue.push_back(core_scheduler.get_current_task_handle());
core_scheduler.block_current_task(None);
}
_ => {
return Ok(());
}
loop {
let mut waiting_tasks_guard = WAITING_TASKS.lock();

if let Some(queue) = waiting_tasks_guard.get_mut(&id) {
queue.push_back(core_scheduler.get_current_task_handle());
core_scheduler.block_current_task(None);

// Switch to the next task.
drop(waiting_tasks_guard);
core_scheduler.reschedule();
} else {
return Ok(());
}
}

// Switch to the next task.
core_scheduler.reschedule();

Ok(())
}

fn get_task_handle(id: TaskId) -> Option<TaskHandle> {
Expand Down

0 comments on commit 51ef3d0

Please sign in to comment.