Subj : Re: Recursive mutexes To : comp.programming.threads From : Mikhail Polatov Date : Wed Mar 23 2005 08:51 pm "notme" writes: > I'm trying to implement in C++ a recursive mutex class, because the > operating > system doesn't provide one (it only provides ordinary mutexes and critical > sections) > So far, I have done this: > > void my_mutex::acquire() { > EnterCriticalSection(); > if (m_owner == thread_id) { > ++m_count; > } > else { > m_mutex->wait(); > m_count = 1; > m_owner = thread_id; > } > ExitCriticalSection(); > } > > void my_mutex::release() { > EnterCriticalSection(); > --m_count; > if (m_count == 0) > m_mutex->signal(); > ExitCriticalSection(); > } > > I guess the variable's names are self-explanatory. Is this implementation > ok? I'd like to hear from the experts here > any comment or advice about corrections, performance changes, etc. Remember > that I can only use > these primitives. > > Thanks! > Why do you need a recursive mutex in the first place? You can always refactor your code not to use them plus you'll get the faster code. -- Mikhail Polatov .