Subj : Re: Recursive mutexes To : comp.programming.threads From : doug Date : Sun Mar 27 2005 12:34 pm I think you were very close with your first attempt. Try this: 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(); } void my_mutex::release() { EnterCriticalSection(); --m_count; if (m_count == 0) * { * m_owner = 0; m_mutex->signal(); * } ExitCriticalSection(); } The * lines are new. The second set is just the bug fix for resetting owner, already pointed out by someone in this thread. The first set will give you what you want and it's multi-cpu safe (provided your OS is). It also demonstrates the cardinal rule of coding with mutexes, signal semphores, etc - "test it before acquiring, and test it again afterwards" - hence the do..while loop, since we have to drop the mutex crit section around wait(). Doug .