Critical section wierdness - or not [edit]


#1

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

As you were…

 Don

#2

…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?

Cheers
Don


#3

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”).