From: simonmar Date: Wed, 12 Oct 2005 12:53:15 +0000 (+0000) Subject: [project @ 2005-10-12 12:53:15 by simonmar] X-Git-Tag: Initial_conversion_from_CVS_complete~179 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=9e10d632f946bae5dd9a9ccd199c8345ca696d15 [project @ 2005-10-12 12:53:15 by simonmar] When blocking on a BLACKHOLE, we must wait until we have finished manipulating the current thread's stack before we release sched_mutex, otherwise another thread can pick up the thread from the blackhole_queue and start running it. --- diff --git a/ghc/rts/HeapStackCheck.cmm b/ghc/rts/HeapStackCheck.cmm index 3635310..ea2d64f 100644 --- a/ghc/rts/HeapStackCheck.cmm +++ b/ghc/rts/HeapStackCheck.cmm @@ -881,6 +881,26 @@ stg_block_putmvar BLOCK_BUT_FIRST(stg_block_putmvar_finally); } +// code fragment executed just before we return to the scheduler +stg_block_blackhole_finally +{ +#if defined(SMP) + // The last thing we do is release sched_lock, which is + // preventing other threads from accessing blackhole_queue and + // picking up this thread before we are finished with it. + foreign "C" RELEASE_LOCK(sched_mutex "ptr"); +#endif + jump StgReturn; +} + +stg_block_blackhole +{ + Sp_adj(-2); + Sp(1) = R1; + Sp(0) = stg_enter_info; + BLOCK_BUT_FIRST(stg_block_blackhole_finally); +} + #ifdef mingw32_HOST_OS INFO_TABLE_RET( stg_block_async, 0/*framesize*/, 0/*bitmap*/, RET_SMALL ) { diff --git a/ghc/rts/StgMiscClosures.cmm b/ghc/rts/StgMiscClosures.cmm index 30088e0..72c5824 100644 --- a/ghc/rts/StgMiscClosures.cmm +++ b/ghc/rts/StgMiscClosures.cmm @@ -343,6 +343,7 @@ INFO_TABLE(stg_BLACKHOLE,0,1,BLACKHOLE,"BLACKHOLE","BLACKHOLE") #if defined(SMP) foreign "C" ACQUIRE_LOCK(sched_mutex "ptr"); + // released in stg_block_blackhole_finally #endif /* Put ourselves on the blackhole queue */ @@ -353,12 +354,7 @@ INFO_TABLE(stg_BLACKHOLE,0,1,BLACKHOLE,"BLACKHOLE","BLACKHOLE") StgTSO_why_blocked(CurrentTSO) = BlockedOnBlackHole::I16; StgTSO_block_info(CurrentTSO) = R1; -#if defined(SMP) - foreign "C" RELEASE_LOCK(sched_mutex "ptr"); -#endif - - /* stg_gen_block is too heavyweight, use a specialised one */ - jump stg_block_1; + jump stg_block_blackhole; } #if defined(PAR) || defined(GRAN) @@ -408,6 +404,7 @@ INFO_TABLE(stg_CAF_BLACKHOLE,0,1,CAF_BLACKHOLE,"CAF_BLACKHOLE","CAF_BLACKHOLE") #if defined(SMP) foreign "C" ACQUIRE_LOCK(sched_mutex "ptr"); + // released in stg_block_blackhole_finally #endif /* Put ourselves on the blackhole queue */ @@ -418,12 +415,7 @@ INFO_TABLE(stg_CAF_BLACKHOLE,0,1,CAF_BLACKHOLE,"CAF_BLACKHOLE","CAF_BLACKHOLE") StgTSO_why_blocked(CurrentTSO) = BlockedOnBlackHole::I16; StgTSO_block_info(CurrentTSO) = R1; -#if defined(SMP) - foreign "C" RELEASE_LOCK(sched_mutex "ptr"); -#endif - - /* stg_gen_block is too heavyweight, use a specialised one */ - jump stg_block_1; + jump stg_block_blackhole; } #ifdef EAGER_BLACKHOLING