@synchronized semantics can be synthesized by using existing mutex_[un]lock operations.
@synchronized(obj) { // ... } => { mutex_lock(obj); // ... mutex_unlock(obj); }
Let me know whether you think this a good idea.
Differential D55959
[TSan] Enable detection of lock-order-inversions for Objective-C @synchronized yln on Dec 20 2018, 3:11 PM. Authored by
Details
@synchronized semantics can be synthesized by using existing mutex_[un]lock operations. @synchronized(obj) { // ... } => { mutex_lock(obj); // ... mutex_unlock(obj); } Let me know whether you think this a good idea.
Diff Detail
Event TimelineComment Actions Added test for recursive @synchronized blocks, that is, nested @synchronized on the same object. This tests proves lock recursiveness. Directly #include <objc/objc-sync.h>. Had to change parameter type from void *obj to id obj in the interceptors to avoid error: conflicting types for 'objc_sync_enter'.
Comment Actions Addressed most comments and added failing test for @synchronize with tagged pointers. Comment Actions I would like to land this and fix @synchronized with tagged pointers in a follow-up since more discussion is required what we actually want it to do. Comment Actions
It's fine with me code-wise, but if we release this without follow up changes it will break real programs. If Kuba is OK with it, go ahead and commit. Comment Actions Create diff via arcanist
Comment Actions Trying to arc diff on git monorepo and arc patch && arc commit on svn working copy is painful, because path is longer on monorepo. |
Can we just #include <objc-sync.h> instead?