Subj : Re: Recursive mutexes To : comp.programming.threads From : doug Date : Sun Mar 27 2005 07:46 pm "Marcin 'Qrczak' Kowalczyk" wrote in message news:87psxl6yfc.fsf@qrnik.zagroda... > "doug" writes: > >> void my_mutex::acquire() { >> EnterCriticalSection(); >> if (m_owner == thread_id) { >> ++m_count; >> } >> else { >> do >> * { >> * ExitCriticalSection(); >> m_mutex->wait(); >> * EnterCriticalSection(); >> * } while (m_count > 0); >> m_count = 1; >> m_owner = thread_id; >> } >> ExitCriticalSection(); >> } > > It should be while (m_count > 0) {...}, not do {...} while (m_count > 0). > > Alternatively m_count should be tested at the beginning, so the common > case of the mutex being free is faster. Indeed it should! This is what you get for making it up on the fly on a Sunday morning after a heavy night out. > > -- > __("< Marcin Kowalczyk > \__/ qrczak@knm.org.pl > ^^ http://qrnik.knm.org.pl/~qrczak/ .