Subj : Re: Recursive mutexes To : comp.programming.threads From : notme Date : Sat Mar 26 2005 08:19 pm >> Not in my system. Why you assume I'm using windows? :-) > > DOH! > > I instantly thought windows because you used EnterCriticalSection. I > failed to see the call to ExitCriticalSection. Windows has > EnterCriticalSection/LeaveCriticalSection API's. Thats what confuused me. No problem :-) > Ok, you can do it like this: > > > void my_mutex::acquire() { > if (m_owner == thread_id) { > ++m_count; > return; > } > > EnterCriticalSection(); > m_owner = thread_id; > } Interesting approach! So it seems this can be done with just one synch object!? > void my_mutex::release() { > if (m_count) { > --m_count; > if ( m_count ) { return; } > } > > m_owner = 0; > ExitCriticalSection(); > } Any advantages if enforcing the if with "&& m_owner == thread_id" ? In any case, it should be expected the code not being ill behaved. Or I could add this check and display an error, right? Thank you very much for your help. Very enlightening. .