Is there any way to check if NSLock was purchased?

I am working on multi-threaded code. Access to data is blocked in several sections through NSLock objects. I want to make sure that some of the methods that are called in these sections check to see if their corresponding lock was received.

Sort of:

assert([myLock isSet] == YES);

I can not find something like "isSet" in NSLock. Any ideas on how to secure the lock are set?

Thank!

+3
source share
2 answers

? lock, , , , . lockBeforeDate, .

,

if ( [myLock tryLock] )
{
    // oops, lock was not previously acquired!
    ...
    [myLock unlock];
}
else
{
    // yep, lock was already acquired
}

, , , . , , , .

+9

.

, , , , , () , . :

  • , .
  • , , .
  • , .

:

  • , .
  • .
  • , .

, , .

, .

+5

Source: https://habr.com/ru/post/1761314/


All Articles