So i am doing a bit of multi-threading and so i decided to write a few classes to keep the nasty disgusting windows/X api's away from me.
The classes i wrote were:
[*] Mutex
[*] Lock
[*] Thread
Mutex, when created (or constructed) on windows will initialize a "Critical Section" and contains the functions: Lock and Unlock. Which enter and exit the critical section respectively.
Now the Lock class takes a reference to Mutex in the constructor and locks it and then the destructor will Unlock the mutex. The lock class is to be used as a temporary as this allows for some prevention of deadlock when an exception occurs before you can call Unlock on the mutex (as temporary's live on the stack and die at function return).
Now look at this code:
Code: Select all
int Update()
{
Lock lock(mutex);
while(closing == false)
{
// DO shit
}
return 0;
}
Now notice here, the temporary cannot be killed off because the function does not return until the "closing" becomes true, so the mutex will NOT unlock. Oops, that's the human error!
Ok, so shit gets weird now. The program runs FINE... in the IDE. Outside the IDE, what occurs? oh deadlock! Now, that there is the IDE error.
So i was wondering, can anyone explain to me why the hell it runs perfect in the IDE, both when using the debugger and not using the debugger.