Subj : Re: Recursive mutexes To : comp.programming.threads From : notme Date : Sat Mar 26 2005 08:26 pm >> void my_mutex::acquire() { >> EnterCriticalSection(); >> if (m_owner == thread_id) { >> ++m_count; >> } >> else { >> m_mutex->wait(); > > Why are you waiting for the mutex while holding the critical section? Because I'm newbie with this :-) > How will the thread that holds the mutex release it? Well, after being elegible to run again. I see, that's not good. Any other thread trying to acquire it will be blocked in the critical section... well, in case if it's the same thread, that shouldn't be a problem, because when it tries to re-acquire it's assumed the mutex was hold. And if it's another thread, it will be blocked not in the mutex, but in the critical section. Is it too bad? So the way to go is using Chris' approach I see. >> m_count = 1; >> m_owner = thread_id; >> } >> ExitCriticalSection(); >> } > > Also, your code won't work unless thread IDs are unique in the sense > that the same thread can't have more than one of them. This is true on > most platforms unless you are using thread handles instead of thread > identifiers. Yes, I'm using id's. Thanks for the comments. .