Skip to content

Commit

Permalink
Correctly shutdown all scheduler threads (#4549)
Browse files Browse the repository at this point in the history
Prior to this change, it was possible to not shutdown all scheduler
threads. ponyint_thread_join on non-Windows systems calls pthread_join.
pthread_join can fail and that failure needs to be handled. In our case
here, given that ponyint_thread_join returns a boolean, the response to
an error is to try again.

If we encounter a non-recoverable error, this new strategy should result
in a hang rather than undefined behavior. If we have hangs that we trace
to this changed functionality, we look at more robust error handling and
changing the interface from ponyint_thread_join.
  • Loading branch information
SeanTAllen authored Nov 26, 2024
1 parent 592132f commit e7e29b0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/libponyrt/sched/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1158,8 +1158,11 @@ static void ponyint_sched_shutdown()
{
uint32_t start = 0;

for(uint32_t i = start; i < scheduler_count; i++)
ponyint_thread_join(scheduler[i].tid);
while(start < scheduler_count)
{
if (ponyint_thread_join(scheduler[start].tid))
start++;
}

DTRACE0(RT_END);
ponyint_cycle_terminate(&this_scheduler->ctx);
Expand Down

0 comments on commit e7e29b0

Please sign in to comment.