summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-09-27 15:49:19 +0000
committerMoritz Angermann <moritz.angermann@gmail.com>2020-09-18 07:33:41 +0000
commitc89d0ef2822a9863c49f3006f80cca041a71d592 (patch)
tree8e2ef637e21657dc4d850ca85e2b270320e3aa15
parent304d4078ca53aebb689a6db7d51a6123a76e99b7 (diff)
downloadhaskell-c89d0ef2822a9863c49f3006f80cca041a71d592.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.
-rw-r--r--rts/Schedule.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/rts/Schedule.c b/rts/Schedule.c
index 15409b044d..d987aa5589 100644
--- a/rts/Schedule.c
+++ b/rts/Schedule.c
@@ -634,6 +634,9 @@ 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 (right?).
+ TSAN_ANNOTATE_BENIGN_RACE(&cap->n_returning_tasks, "shouldYieldCapability");
return ((pending_sync && !didGcLast) ||
cap->n_returning_tasks != 0 ||
(!emptyRunQueue(cap) && (task->incall->tso == NULL
@@ -721,7 +724,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!