How to test a synchronization object for lock?
-
Hi, I am using CCriticalSection and CSingleLock for synchronization purpose. Is there a mechanism to test the synchronization object to know whether it is locked from another thread? That is, I don't want to enter the lock, but just want to know whether the synchronization object is locked or not without blocking my code.
-
Hi, I am using CCriticalSection and CSingleLock for synchronization purpose. Is there a mechanism to test the synchronization object to know whether it is locked from another thread? That is, I don't want to enter the lock, but just want to know whether the synchronization object is locked or not without blocking my code.
There would be a solution by getting the lock count from the undocumented
_RTL_CRITICAL_SECTION
structure. But there should be no reason to do that when using locks as intended (for short periods). For longer periods use other mechanisms like events.