Subj : Re: Recursive mutexes To : comp.programming.threads From : Chris Thomasson Date : Thu Mar 24 2005 03:51 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. >(In fact, AFAIK, windows does support recursive mutexes). Yes it does. > No, in my case they're implemented with a semaphore, so calling it twice > in a row > in the same thread would deadlock. This is an embedded system, and the > synchronization support > isn't very good. It's quite minimal. This is why I need to do it by > myself. Ok, you can do it like this: void my_mutex::acquire() { if (m_owner == thread_id) { ++m_count; return; } EnterCriticalSection(); m_owner = thread_id; } void my_mutex::release() { if (m_count) { --m_count; if ( m_count ) { return; } } m_owner = 0; ExitCriticalSection(); } .