Critical section wierdness - or not [edit]

…never mind. Post deleted as in writing it I think I have a clue as to what is going wrong.

As you were…


…and an interesting snippet from the documentation:

CriticalSection::~CriticalSection() throw () Destroys a CriticalSection object. If the critical section is deleted whilst locked, its subsequent behaviour is unpredictable.

‘Subsequent behaviour’? It has just been deleted… hence it does not have any subsequent behaviour right?


A CriticalSection supports recursion. That means the same thread can enter it multiple times without getting blocked.

The number of calls to exit() must match the number of calls to enter() in order for ownership of the CriticalSection to be released.

It means that if a CriticalSection object is destroyed while a thread has ownership via enter(), that the resulting behavior of the application is UB (“Undefined Behavior”).