Sometimes I wrote the following code to synchronized a routine:
@synchronized(objToBeSync){ .... }
When two threads try to access the sync block at the same time, one will block the others, until the one exits the sync block.
However, sometimes I don't want one blocks the other, but the others check if the object is being synchronized, and then do some other thing so I have to do sth like this:
@synchronized(objToBeSync){
_isBeingSync = YES;
...
_isBeingSync = NO;
}
_isBeingSync
is an additional var on checking if objToBeSync is being sync. The other threads check _isBeingSync
before they continue their work. And my question is that does objc provide sth to check objToBeSync directly but not introduce an additional var to mark down its status.