Currently (with iOS 8 and OS X 10.10) internally, all associations are atomically generated. This can be seen if you look at the source objc-references.mm:
class AssociationsManager {
static spinlock_t _lock;
static AssociationsHashMap *_map;
public:
AssociationsManager() { spinlock_lock(&_lock); }
~AssociationsManager() { spinlock_unlock(&_lock); }
AssociationsHashMap &associations() {
if (_map == NULL)
_map = new AssociationsHashMap();
return *_map;
}
};
In particular, note that _lockboth _mapare static and are defined as such:
spinlock_t AssociationsManager::_lock = SPINLOCK_INITIALIZER;
AssociationsHashMap *AssociationsManager::_map = NULL;
And then when both get the association and release it, we see the following:
AssociationsManager manager;
AssociationsHashMap &associations(manager.associations());
, , .
, , , , , .