Hi,
In my class, I need to lock access to a member object which is not thread safe, since the my class may be accessed from several threads using the same object. Lets call my class CClass, and the object m_obj. Now, in order to make it thread-safe, I have create a CCriticalSection member variable, which, for now, I lock using CSingleLock. The scenario is as follows:
I have a function X, which does some things with m_obj and then calls function Y, which also messes with m_obj. I know the lock still persists when Y() is executed since CSingleLock didn't go out of scope (since X() still waits on the call to Y()), but I need Y() to perform a lock by itself since it may be called independantly of X() directly from the executing thread.
My question is: when I will try and lock the CCriticalSection (with or without CSingleLock) would the call to Lock() return immediately since the current thread already locked that criticalsection, or would it wait on a lock to return after it has been unlocked? (hence, result in an infinite lock?)
I know thats a bit comlicated question. Let me know if you need anymore details or clarifications. Thanks!
Stilgar.
Start Free Trial