summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marlow <simonmarhaskell@gmail.com>2008-04-16 22:10:02 +0000
committerSimon Marlow <simonmarhaskell@gmail.com>2008-04-16 22:10:02 +0000
commit96195367ad299bc3be251535bcff7fb75d097e07 (patch)
tree48483dfd98eafe0d3bfca70ba10853cf810b4683
parentbaf34c5931e931566d0a6d3f892db43db7ed8f46 (diff)
downloadhaskell-96195367ad299bc3be251535bcff7fb75d097e07.tar.gz
wait for threads to start up properly
-rw-r--r--rts/sm/GC.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/rts/sm/GC.c b/rts/sm/GC.c
index 722de0facc..1ac27f21e8 100644
--- a/rts/sm/GC.c
+++ b/rts/sm/GC.c
@@ -978,7 +978,8 @@ alloc_gc_thread (int n)
t->id = 0;
initCondition(&t->wake_cond);
initMutex(&t->wake_mutex);
- t->wakeup = rtsFalse;
+ t->wakeup = rtsTrue; // starts true, so we can wait for the
+ // thread to start up, see wakeup_gc_threads
t->exit = rtsFalse;
#endif
@@ -1189,7 +1190,16 @@ wakeup_gc_threads (nat n_threads USED_IF_THREADS)
nat i;
for (i=1; i < n_threads; i++) {
inc_running();
- ACQUIRE_LOCK(&gc_threads[i]->wake_mutex);
+ debugTrace(DEBUG_gc, "waking up gc thread %d", i);
+ do {
+ ACQUIRE_LOCK(&gc_threads[i]->wake_mutex);
+ if (gc_threads[i]->wakeup) {
+ RELEASE_LOCK(&gc_threads[i]->wake_mutex);
+ continue;
+ } else {
+ break;
+ }
+ } while (1);
gc_threads[i]->wakeup = rtsTrue;
signalCondition(&gc_threads[i]->wake_cond);
RELEASE_LOCK(&gc_threads[i]->wake_mutex);