RE: [reSIProcate] Mutex.cpp and RecursiveMutex.cpp Implementation s for Win32
OK - I've done a bunch of research on the race condition in Condition.cpp
for windows users and came up with the following analysis:
A Note about the Win32 Implementation of Conditions
===================================================
I have investigated a fix for this. A solution to this problem is
non-trivial. Please read http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
for a full explanation. We currently use an implementation of the SetEvent
solution discussed in that article. This solution has the following issues:
1. Unfairness - ie. First thread to call wait may not be first thread to
be released from condition.
2. Incorrectness due to a race condition when a broadcast occurs
(see the link for more details on these issues)
There is a solution that corrects these two problems, but also introduces 2
more. This solution (also discussed in the link) requires the use of a
primitive only available in WinNT and above (SignalObjectAndWait). It also
requires that the Mutex passed in be implemented using windows Mutexes
instead of CriticalSections - and they are less efficient. Thus the
problems with this SignalObjectAndWait solution are:
1. Not portable to all versions of windows - ie. will not work with
Win98/Me.
2. Less efficient than the SetEvent solution - more overhead
Summary:
--------
I propose we stick with the SetEvent Solution for the following reasons:
1. Speed is important.
2. The Unfairness issue is not really a big problem since the stack
currently does not call a wait function from two different threads.
(assuming the hosting application always calls process() from the same
thread). The only time multi-threading comes into the picture is when the
stack is used in MutliThreaded mode and the transports queue messages from
the wire onto the stateMacFifo - but they are retrieved off the Fifo by a
single thread.
3. The Incorrectness issue is also not a big problem, since the stack
currently doesn't use the broadcast member of this class.
I also propose that the implementation of the broadcast member (for win32)
remains incomplete - since it is currently unused and would require an
additional CriticalSection Enter and Leave to keep track of a counter (see
the above link for more info). This can be easily added in the future if
required.
Any thoughts? I will add these comments to the source file if there is no
opposition.
Thanks,
Scott
-----Original Message-----
From: Ken Kittlitz [mailto:ken@xxxxxxxxxx]
Sent: Tuesday, June 15, 2004 1:40 PM
To: Scott Godin
Cc: resiprocate-devel@xxxxxxxxxxxxxxxxxxx
Subject: Re: [reSIProcate] Mutex.cpp and RecursiveMutex.cpp Implementation s
for Win32
Scott Godin wrote:
>There seems to be an outstanding race condition in Condition.cxx for Win32
-
>comments in code are:
>// FixMe: Race condition between time we get mId and when we
>// re-acquire the mutex.
>I may work on this one, instead.
>
>
>
Thanks! Getting rid of that race condition would be a Good Thing.
-Ken