MAYBE_GC(R1_PTR, forkzh_fast);
+ foreign "C" ACQUIRE_LOCK(sched_mutex "ptr");
+
// create it right now, return ThreadID in R1
"ptr" R1 = foreign "C" createIOThread( RtsFlags_GcFlags_initialStkSize(RtsFlags),
R1 "ptr");
- foreign "C" scheduleThread(R1 "ptr");
+ foreign "C" scheduleThreadLocked(R1 "ptr");
+
+ foreign "C" RELEASE_LOCK(sched_mutex "ptr");
// switch at the earliest opportunity
CInt[context_switch] = 1 :: CInt;
createThread(nat size)
#endif
{
-
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;
}
* on this thread's stack before the scheduler is invoked.
* ------------------------------------------------------------------------ */
-static void
-scheduleThread_(StgTSO *tso)
+void
+scheduleThreadLocked(StgTSO *tso)
{
// The thread goes at the *end* of the run-queue, to avoid possible
// starvation of any threads already on the queue.
scheduleThread(StgTSO* tso)
{
ACQUIRE_LOCK(&sched_mutex);
- scheduleThread_(tso);
+ scheduleThreadLocked(tso);
RELEASE_LOCK(&sched_mutex);
}
void awakenBlockedQueueNoLock (StgTSO *tso);
#endif
+/* Version of scheduleThread that doesn't take sched_mutex */
+void scheduleThreadLocked(StgTSO *tso);
+
/* unblockOne()
*
* Takes a pointer to the beginning of a blocked TSO queue, and