Skip to content

Commit

Permalink
proc: Fix race condition when there are many reapers
Browse files Browse the repository at this point in the history
Use broadcast instead of plain wakeup to make sure no
reaper is left waiting, even though it's thread already
ended, or there're no threads to reap anymore.

JIRA: RTOS-762
  • Loading branch information
agkaminski committed Feb 1, 2024
1 parent 24e8386 commit 9cc5f71
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions proc/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ static void thread_destroy(thread_t *thread)

LIST_REMOVE_EX(&process->threads, thread, procnext, procprev);
LIST_ADD_EX(&process->ghosts, thread, procnext, procprev);
_proc_threadWakeup(&process->reaper);
_proc_threadBroadcast(&process->reaper);

hal_spinlockClear(&threads_common.spinlock, &sc);
proc_put(process);
Expand Down Expand Up @@ -976,9 +976,10 @@ void proc_reap(void)
spinlock_ctx_t sc;

hal_spinlockSet(&threads_common.spinlock, &sc);
while ((ghost = threads_common.ghosts) == NULL)
while (threads_common.ghosts == NULL) {
_proc_threadWait(&threads_common.reaper, 0, &sc);

}
ghost = threads_common.ghosts;
LIST_REMOVE(&threads_common.ghosts, ghost);
hal_spinlockClear(&threads_common.spinlock, &sc);

Expand Down

0 comments on commit 9cc5f71

Please sign in to comment.