Why is MutexHandle::lock() non-blocking by default?
by Lateral Punk · in Torque Game Engine · 06/02/2006 (7:54 pm) · 5 replies
Just noticed something extremely weird. MutexHandle::lock is defined as such:
but then the code for Mutex::lockMutex() is defined as such:
What is the handle set to blocking false and the actual mutex set to true by default? It seems inconsistent in my opionion. And definitely gives unexpected behaviour for first time users. I put mutexes around my code, and two threads were still going in. I was at total lost, until I saw that the handle by default is set not to blocking. Am I missing something here?
bool lock(void *mutex, bool blocking=false)
{
AssertFatal(!mMutexPtr, "MutexHandle::lock - shouldn't be locking things twice!");
bool ret = Mutex::lockMutex(mutex, blocking);
if(ret)
{
// We succeeded, do book-keeping.
mMutexPtr = mutex;
}
return ret;
}but then the code for Mutex::lockMutex() is defined as such:
static bool lockMutex( void *mutex, bool block = true);
What is the handle set to blocking false and the actual mutex set to true by default? It seems inconsistent in my opionion. And definitely gives unexpected behaviour for first time users. I put mutexes around my code, and two threads were still going in. I was at total lost, until I saw that the handle by default is set not to blocking. Am I missing something here?
#2
06/03/2006 (11:11 am)
Thanks for the information. I'll probably just keep the "typo" in for backwards compatibility. Or do you think this will be addressed as a bug?
#4
06/04/2006 (11:42 am)
So Ben, wouldn't that mean that whereever you were using MutexHandles currently in 1.4 wasn't really resulting in the behaviour you expected (ie. threads were not blocking when required and it wasn't really producing thread-safe code?).
#5
Not neccessarily. I've hammered on the thread code a lot and have already fixed a few issues that came up post-1.4. If this was a problem, I'd probably have found it by now. Of course, that doesnt mean that it definately isnt a problem, so it should still be double checked.
T.
06/04/2006 (2:17 pm)
@LateralPunk,Not neccessarily. I've hammered on the thread code a lot and have already fixed a few issues that came up post-1.4. If this was a problem, I'd probably have found it by now. Of course, that doesnt mean that it definately isnt a problem, so it should still be double checked.
T.
Torque 3D Owner Tom Bampton
If you change the default behavior, then its a good idea to double check all existing uses of it. MutexHandle came about to simplify a lot of code in the sim and console so it's used quite a bit.
T.