I think I have misunderstood how CmtGetLock/CmtGetLockEx works. I have my main code and some functions called from asynchronous timers. I am locking messaging routines (only one I2C port to write/read to 😉 using CmtGetLockEx but now that I put in DebugPrintfs, I see it's allowing multiples to access it.
In a simple test, I would have expected the second lock to block because it's already claimed:
CmtThreadLockHandle lockHandle;
int RetVal;
RetVal = CmtNewLock (NULL, 0, &lockHandle);
if (RetVal == 0) // Success
{
RetVal = CmtGetLock (lockHandle);
RetVal = CmtGetLock (lockHandle);
RetVal = CmtGetLock (lockHandle);
RetVal = CmtGetLock (lockHandle);
RetVal = CmtGetLock (lockHandle);
}
exit(0);
But instead, each CmtGetLock returns success. What am I missing? In other environments I have worked on, if a semaphore is claimed, you block if you try to claim it again. The help file mentions:
"You can call this function from the same thread more than once, but you must call CmtReleaseLock once for each time that you called this function."
Does this mean it only works between separate threads? I am using asynchronous timers and some of my functions are called from one of them.
Thoughts?