< Previous by Date Date Index Next by Date >
< Previous in Thread Thread Index  

RE: [reSIProcate] Mutex.cpp and RecursiveMutex.cpp Implementation s for Win32


I just want to clarify my understanding of the purpose of the RecursiveMutex
class.  I am assuming the intent of this class is to provide a Mutex
implementation that is re-entrant by a thread.  Ie.  If the same thread
locks the same mutex twice it will not deadlock.  If this is correct then
this is the default behavior of Windows Mutex implementation.  See the
following from MSDN: 

"The thread that owns a mutex can specify the same mutex in repeated wait
function calls without blocking its execution. Typically, you would not wait
repeatedly for the same mutex, but this mechanism prevents a thread from
deadlocking itself while waiting for a mutex that it already owns. However,
to release its ownership, the thread must call ReleaseMutex once for each
time that the mutex satisfied a wait."

Also - I was considering changing the implementation of Mutex to using
windows Critical Sections, which are also thread re-entrant and are supposed
to be more efficient.  See the following from MSDN:

"Critical section objects provide synchronization similar to that provided
by mutex objects, except that critical section objects can be used only by
the threads of a single process. Event, mutex, and semaphore objects can
also be used in a single-process application, but critical section objects
provide a slightly faster, more efficient mechanism for mutual-exclusion
synchronization (a processor-specific test and set instruction). Like a
mutex object, a critical section object can be owned by only one thread at a
time, which makes it useful for protecting a shared resource from
simultaneous access. There is no guarantee about the order in which threads
will obtain ownership of the critical section, however, the system will be
fair to all threads. Unlike a mutex object, there is no way to tell whether
a critical section has been abandoned. .....
Once a thread owns a critical section, it can make additional calls to
EnterCriticalSection or TryEnterCriticalSection without blocking its
execution. This prevents a thread from deadlocking itself while waiting for
a critical section that it already owns."

Any thoughts? 

Thanks,

Scott


-----Original Message-----
From: david Butcher [mailto:david@xxxxxxxxxxxxxx] 
Sent: Tuesday, June 15, 2004 3:47 PM
To: resiprocate-devel@xxxxxxxxxxxxxxxxxxx
Subject: RE: [reSIProcate] Mutex.cpp and RecursiveMutex.cpp Implementation s
for Win32

Quoting Scott Godin <slgodin@xxxxxxxxxxxx>:

> I did a quick search and it looks like RecursiveMutex is not used anywhere
> in the stack anyway.
> 

RecursiveMutex was proposed (but sadly not implemented) for dealing with
recursive logging. Recursive logging now asserts. This is better than
deadlocking, but actually logging recursively would be much more useful.

david
_______________________________________________
resiprocate-devel mailing list
resiprocate-devel@xxxxxxxxxxxxxxxxxxx
https://list.sipfoundry.org/mailman/listinfo/resiprocate-devel