开发者

wxCriticalSection under Linux/Unix

i discovered that a wxCriticalSection is not recursive ( does deadlock when a thread grabs a section more than once ) under linux. Looking at the sources, i discovered that a wxCriticalSection is implemented using a wxMutex under Linux, but without using wxMUTEX_RECURSIVE. I have a codebase that runs well under Win and Mac, and i want to port it to Linux, but i have deadlocks at some places where i did not avoid recursion.

No开发者_如何学运维w i have two possibilities:

  1. Changing and rebuilding wxWidgets for my purpose ( brrr - by any chance i want to avpid that since i do not know too much about the design decisions behind that )

  2. debugging each and all of my possible code paths ( brrr - will take days and is horribly bug - prone )

Is there a third way, replacing/extending wxCriticalSection with a construct that behaves equally under Mac/Win/Unix?

ps. could someone explain the design decision to me? Mr. Vadim Z says ...

I had temporarily forgot the reason I was against this (making wxCriticalSections recursive) but I did recall it 30 seconds later (after sending my message, of course ). Please see my follow-up

But there was never a follow-up ...


In version 2.9.1, it appears that the default should be recursive. In file \wxWidgets-2.9.1\include\wx\thread.h:

inline wxCriticalSection::wxCriticalSection( wxCriticalSectionType critSecType )
   : m_mutex( critSecType == wxCRITSEC_DEFAULT ? wxMUTEX_RECURSIVE : wxMUTEX_DEFAULT )  { }

And in class wxCriticalSection the constructor declaration is

wxCRITSECT_INLINE wxCriticalSection( wxCriticalSectionType critSecType = wxCRITSEC_DEFAULT );

I don't use Linux, so I can't verify that wxCriticalSection is actually recursive when compiled.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜