No. It wont block on the second call, unless the second call is made from a different thread. Mutexes are designed to prevent different threads accessing the same data, concurrently.
Depending on the type of mutex created, you may have to LeaveMutex() the same number of times as you entered it (per thread) before another thread will be able to enterMutex on it.
So you code probably just locks the mutex twice, and another thread will block on the mutex until the first thread unlocks it twice.
Events are different babies altogether. The code (calling wait) will block until another thread signals the Event.
You might want to use this in a thread that runs an endless loop, but to save processor power, waits on the event, before continuing its loop.The event would be signalled when another thread determines that the waiting thread has something to do, i.e. process a message!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all.
I have a problem.
The following code:
ost::Mutex m;
m.enterMutex();
m.enterMutex();
should lock on the second call, right?
Well It doesnt under Linux nor under Windows.
Im using the latest release 2.0.95
Im I lost here or?
The following works:
ost::Event e;
e.reset();
e.wait();
It locks alright.
No. It wont block on the second call, unless the second call is made from a different thread. Mutexes are designed to prevent different threads accessing the same data, concurrently.
Depending on the type of mutex created, you may have to LeaveMutex() the same number of times as you entered it (per thread) before another thread will be able to enterMutex on it.
So you code probably just locks the mutex twice, and another thread will block on the mutex until the first thread unlocks it twice.
Events are different babies altogether. The code (calling wait) will block until another thread signals the Event.
You might want to use this in a thread that runs an endless loop, but to save processor power, waits on the event, before continuing its loop.The event would be signalled when another thread determines that the waiting thread has something to do, i.e. process a message!