From 598472908ebb08f6811b892f285490554c290ae3 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Sat, 3 Jun 2017 20:26:13 +0100 Subject: Fix a lost-wakeup bug in BLACKHOLE handling (#13751) Summary: The problem occurred when * Threads A & B evaluate the same thunk * Thread A context-switches, so the thunk gets blackholed * Thread C enters the blackhole, creates a BLOCKING_QUEUE attached to the blackhole and thread A's `tso->bq` queue * Thread B updates the blackhole with a value, overwriting the BLOCKING_QUEUE * We GC, replacing A's update frame with stg_enter_checkbh * Throw an exception in A, which ignores the stg_enter_checkbh frame Now we have C blocked on A's tso->bq queue, but we forgot to check the queue because the stg_enter_checkbh frame has been thrown away by the exception. The solution and alternative designs are discussed in Note [upd-black-hole]. This also exposed a bug in the interpreter, whereby we were sometimes context-switching without calling `threadPaused()`. I've fixed this and added some Notes. Test Plan: * `cd testsuite/tests/concurrent && make slow` * validate Reviewers: niteria, bgamari, austin, erikd Reviewed By: erikd Subscribers: rwbarton, thomie GHC Trac Issues: #13751 Differential Revision: https://phabricator.haskell.org/D3630 --- rts/Schedule.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'rts/Schedule.c') diff --git a/rts/Schedule.c b/rts/Schedule.c index f82d924183..b4f60f8d3a 100644 --- a/rts/Schedule.c +++ b/rts/Schedule.c @@ -1215,10 +1215,9 @@ scheduleHandleYield( Capability *cap, StgTSO *t, uint32_t prev_what_next ) ASSERT(t->_link == END_TSO_QUEUE); - // Shortcut if we're just switching evaluators: don't bother - // doing stack squeezing (which can be expensive), just run the - // thread. - if (cap->context_switch == 0 && t->what_next != prev_what_next) { + // Shortcut if we're just switching evaluators: just run the thread. See + // Note [avoiding threadPaused] in Interpreter.c. + if (t->what_next != prev_what_next) { debugTrace(DEBUG_sched, "--<< thread %ld (%s) stopped to switch evaluators", (long)t->id, what_next_strs[t->what_next]); -- cgit v1.2.1