Skip to content

Commit

Permalink
Fix scheduler suspend edge case assertion
Browse files Browse the repository at this point in the history
Prior to this commit, it was possible for a scheduler thread to
suspend even though it wasn't appropriate to do so because
another scheduler thread resumed prior to the lock being
acquired. This would result in incorrect behavior in the
release build and an assertion in the debug build.

See the following link for an example of the assertion being
triggered: https://circleci.com/gh/ponylang/ponyc/3809?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

This commit fixes the issue by not suspending if the schduler
count changed because another thread resumed.
  • Loading branch information
dipinhora committed Apr 10, 2018
1 parent 84a9901 commit a3ab554
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/libponyrt/sched/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,10 @@ static pony_actor_t* suspend_scheduler(scheduler_t* sched,
memory_order_relaxed);

// make sure the scheduler count didn't change
pony_assert(sched_count == current_active_scheduler_count);
(void)current_active_scheduler_count;
// if it did, then another thread resumed and it may not be
// appropriate for us to suspend any longer, so don't suspend
if(sched_count != current_active_scheduler_count)
return actor;

atomic_store_explicit(&active_scheduler_count, sched_count - 1,
memory_order_relaxed);
Expand Down

0 comments on commit a3ab554

Please sign in to comment.