I'm developing an iOS app and need to implement a solution for a problem for which I need to know how many threads are waiting for locking the same NSLock object.
In Java I have the class ReentrantLock, with the method getQueueLength, which "Returns an estimate of the number of threads waiting to acquire this lock."
Is there something similar in Objective-C? I've tried to find something, but nothing. Should I subclass NSLock for implementing this mechanism by myself?
Look at OSAtomic.h. You can create a global counter, then before a thread tries to get the lock increment it, then decrement afterwards. To read the current value you "add" 0 to it and look at the return value. I have used these for years on both OSX and ios.