From 3418a8bcbe3b6c61f38e1b5721e644f94e7bb6ba Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 28 Nov 2009 15:24:02 -0700 Subject: [PATCH] fix race condition introduced in previous commit --- src/machine.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index 20c3b43d50..cdb12a5219 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -2421,10 +2421,18 @@ enter(Thread* t, Thread::State s) if (t->state == Thread::IdleState and t->m->exclusive == 0) { // fast path INCREMENT(&(t->m->activeCount), 1); - t->state = s; - break; - } else { - ACQUIRE_LOCK; + + if (t->m->exclusive) { + // a thread has entered exclusive mode - switch to slow path + assert(t, t->m->activeCount > 0); + INCREMENT(&(t->m->activeCount), -1); + } else { + t->state = s; + break; + } + } + + { ACQUIRE_LOCK; switch (t->state) { case Thread::ExclusiveState: {