The compiler translates @synchronized(objToBeSync) { ... } to
callq _objc_sync_enter ... callq _objc_sync_exit
and from Objective-C the runtime source code (objc-sync.mm, objc-os.mm, objc-lockdebug.mm, objc-os.h) you can see that these functions basically perform
pthread_mutex_lock(m->mutex); ... pthread_mutex_unlock(m->mutex);
where m->mutex is pthread_mutex_t with the PTHREAD_MUTEX_RECURSIVE attribute that is associated with the objToBeSync object using a cache internal to the runtime.
Thus, a direct answer to your question: No, there is no public API to get the "blocked" status of an object, and access to the internal mutex seems almost impossible for me.
Therefore, you should use a different locking mechanism if you have this requirement, for example Mutex Posix Lock, NSLock or NSRecursiveLock . All these locks have a “try” method, which can be used to access the lock or immediately crash without locking.
See “Thread Programming Guide: Synchronization” for an overview.
Note that @synchronized (unlike other locking mechanisms) implicitly adds an exception handler to the block, so the mutex is freed if an exception is thrown.
Also @synchronized is a recursive lock, i.e. the same thread can enter the protected code without blocking. If this is relevant to your code, you will have to use NSRecursiveLock or Lock Mutex Posix with the "recursive" attribute.
Please note that using a simple _isBeingSync instance _isBeingSync for this purpose is race-specific and will not work safely.