Fix lock-ordering during init (#237)
Reorders how locking is handled in `objc_send_initialize()` to prevent a deadlock. Previously, contention on the low level spinlocks could cause a very intermittent deadlock: - Thread A : `objc_send_initialize()` holds the runtime lock, then tries to acquire the object lock on the metaclass, which needs to initialize the mutex for the new metaclass inside `referenceListForObject()`, so it tries to lock the `lock_for_pointer()` / `lock_spinlock()` - Thread B : `referenceListForObject()` holds a spinlock for an unrelated object while running `initHiddenClassForObject()` -> `allocateHiddenClass()`, which tries to acquire the runtime lock If the metaclass object pointer in Thread A hashes to the same spinlock as the object in thread B, the runtime lock ends up deadlocked forever.main
parent
8c600f5b56
commit
cd50e72f81
Loading…
Reference in New Issue