wxCriticalSection - different behaviour on Linux & Windows
Vadim Zeitlin
vadim at wxwindows.org
Fri Jun 1 06:43:10 PDT 2007
On Thu, 31 May 2007 23:54:11 +0200 Robert Roebling wrote:
RR> Arne Steinarson wrote:
RR>
RR> > This has been up for discussion before, but its worth to
RR> > look at it again:
RR>
RR> I see mentioning of this problem, but not any discussion
RR> why the code does what it currently does.
Simple: this is the native behaviour. Critical sections are reentrant
under Win32 while POSIX mutexes are not. For me the latter behaviour makes
much more sense and in my own code I almost always wrap CRITICAL_SECTION
into a class checking that it's not reentered.
RR> > Now: It seems very unsafe to have a class with different semantics on
RR> > different platforms. This behaviour invites subtle bugs, that can be
RR> > hard to track down.
Yes, I agree. However if we want to fix it, I'd rather make critical
sections not reentrant (well, not really, but at least add an assert) than
using reentrant mutexes.
RR> > I understand that recursive mutexes made their way into wxw after the
RR> > wxCriticalSection.
Not only this, but recursive mutexes can't be used with condition
variables, at least on some platforms (see the comment in front of
wxMUTEX_RECURSIVE definition) so wxMutex class can't use recursive mutexes
by default.
RR> Anyways, I'd favour correcting wxCriticalSection as you say,
RR> the question is mostly: in which branch?
For me the best way to correct this would be to
(a) make wxCriticalSection assert if you try to reenter it under Windows
(under Unix it already won't work)
(b) add wxReentrantCriticalSection (or another class with a better name)
doing what it says under all platforms
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
More information about the wx-users
mailing list