cap = myCapability();
#endif
- // We have run some Haskell code: there might be blackhole-blocked
- // threads to wake up now.
- if ( blackhole_queue != END_TSO_QUEUE ) {
- blackholes_need_checking = rtsTrue;
- }
-
cap->r.rInHaskell = rtsFalse;
// The TSO might have moved, eg. if it re-entered the RTS and a GC
#endif
ACQUIRE_LOCK(&sched_mutex);
+
+ // We have run some Haskell code: there might be blackhole-blocked
+ // threads to wake up now.
+ if ( blackhole_queue != END_TSO_QUEUE ) {
+ blackholes_need_checking = rtsTrue;
+ }
#if defined(RTS_SUPPORTS_THREADS)
IF_DEBUG(scheduler,debugBelch("sched (task %p): ", osThreadId()););
StgTSO *tso;
nat stack_size;
+ ACQUIRE_LOCK(&sched_mutex);
+
/* First check whether we should create a thread at all */
#if defined(PARALLEL_HASKELL)
/* check that no more than RtsFlags.ParFlags.maxThreads threads are created */
threadsIgnored++;
debugBelch("{createThread}Daq ghuH: refusing to create another thread; no more than %d threads allowed (currently %d)\n",
RtsFlags.ParFlags.maxThreads, advisory_thread_count);
+ RELEASE_LOCK(&sched_mutex);
return END_TSO_QUEUE;
}
threadsCreated++;
IF_DEBUG(scheduler,sched_belch("created thread %ld, stack size = %lx words",
(long)tso->id, (long)tso->stack_size));
#endif
+ RELEASE_LOCK(&sched_mutex);
return tso;
}
/* Actually this is not necessary because R1 is about to be destroyed. */
LDV_ENTER(R1);
+#if defined(SMP)
+ foreign "C" ACQUIRE_LOCK(sched_mutex "ptr");
+#endif
+
/* Put ourselves on the blackhole queue */
StgTSO_link(CurrentTSO) = W_[blackhole_queue];
W_[blackhole_queue] = CurrentTSO;
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;
}
TICK_ENT_BH();
LDV_ENTER(R1);
+#if defined(SMP)
+ foreign "C" ACQUIRE_LOCK(sched_mutex "ptr");
+#endif
+
/* Put ourselves on the blackhole queue */
StgTSO_link(CurrentTSO) = W_[blackhole_queue];
W_[blackhole_queue] = CurrentTSO;
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;
}