I am working on multithreaded code. Data access is locked in several sections via “NSLock” objects. I want to ensure that some methods which are called within these sections check if their appropriate lock was aquired.
Something like:
assert([myLock isSet] == YES);
I can’t find something like “isSet” in NSLock. Any ideas how to ensure a lock is set?
Thanks!
How are you acquiring the lock? If you’re calling
lock, then the fact that you’re even running afterwards should guarantee you’ve acquired it. If you calllockBeforeDate, the return value tells you.If you want to test from elsewhere, you could do
However, in general this seems like a questionable thing to want to do. You should do the locking where it’s needed and trust it to work rather than trying to oversee it from the outside.