diff options
author | Ben Gamari <ben@smart-cactus.org> | 2019-09-27 15:49:19 +0000 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2020-10-24 21:00:36 -0400 |
commit | 31fa87ecb4ff1abc761d776d48e87cd0fd37bedd (patch) | |
tree | de26ac3f1c0ee73106c182ee1d93494540e00fa7 /rts/Schedule.c | |
parent | 65219810a41f1c903838185a766baeba8954cc88 (diff) | |
download | haskell-31fa87ecb4ff1abc761d776d48e87cd0fd37bedd.tar.gz |
rts: Use relaxed atomics on n_returning_tasks
This mitigates the warning of a benign race on n_returning_tasks in
shouldYieldCapability.
See #17261.
Diffstat (limited to 'rts/Schedule.c')
-rw-r--r-- | rts/Schedule.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/rts/Schedule.c b/rts/Schedule.c index c04907f157..8af5a51d51 100644 --- a/rts/Schedule.c +++ b/rts/Schedule.c @@ -654,8 +654,11 @@ shouldYieldCapability (Capability *cap, Task *task, bool didGcLast) // Capability keeps forcing a GC and the other Capabilities make no // progress at all. + // We would usually need to hold cap->lock to look at n_returning_tasks but + // we don't here since this is just an approximate predicate. + TSAN_ANNOTATE_BENIGN_RACE(&cap->n_returning_tasks, "shouldYieldCapability"); return ((pending_sync && !didGcLast) || - cap->n_returning_tasks != 0 || + RELAXED_LOAD(&cap->n_returning_tasks) != 0 || (!emptyRunQueue(cap) && (task->incall->tso == NULL ? peekRunQueue(cap)->bound != NULL : peekRunQueue(cap)->bound != task->incall))); @@ -741,7 +744,7 @@ schedulePushWork(Capability *cap USED_IF_THREADS, cap0 = capabilities[i]; if (cap != cap0 && !cap0->disabled && tryGrabCapability(cap0,task)) { if (!emptyRunQueue(cap0) - || cap0->n_returning_tasks != 0 + || RELAXED_LOAD(&cap0->n_returning_tasks) != 0 || !emptyInbox(cap0)) { // it already has some work, we just grabbed it at // the wrong moment. Or maybe it's deadlocked! |