+/************ THREADS version *****************/
+
+void
+startTaskManager( nat maxCount,
+ void (*taskStart)(void) STG_UNUSED )
+{
+ /* In the threaded case, maxCount is used to limit the
+ the creation of worker tasks. Tasks are created lazily, i.e.,
+ when the current task gives up the token on executing
+ STG code.
+ */
+ maxTasks = maxCount;
+ taskCount = 0;
+}
+
+rtsBool
+startTask ( void (*taskStart)(void) )
+{
+ int r;
+ OSThreadId tid;
+
+ /* If more than one worker thread is known to be blocked waiting
+ on thread_ready_cond, don't create a new one.
+ */
+ if ( rts_n_waiting_tasks > 0) {
+ IF_DEBUG(scheduler,debugBelch(
+ "scheduler: startTask: %d tasks waiting, not creating new one.\n",
+ rts_n_waiting_tasks););
+ // the task will run as soon as a capability is available,
+ // so there's no need to wake it.
+ return rtsFalse;
+ }
+
+ /* If the task limit has been reached, just return. */
+ if (maxTasks > 0 && taskCount == maxTasks) {
+ IF_DEBUG(scheduler,debugBelch("scheduler: startTask: task limit (%d) reached, not creating new one.\n",maxTasks));
+ return rtsFalse;
+ }
+
+
+ r = createOSThread(&tid,taskStart);
+ if (r != 0) {
+ barf("startTask: Can't create new task");
+ }
+ taskCount++;
+
+ IF_DEBUG(scheduler,debugBelch("scheduler: startTask: new task %ld (total_count: %d; waiting: %d)\n", tid, taskCount, rts_n_waiting_tasks););
+ return rtsTrue;
+}
+
+
+