os_unfair_lock
Peter Steinberger measured the new os_unfair_lock
against OSSpinLock
, pthread_mutex
, NSLock
, dispatch queues, and @synchronized
.
Pierre Habouzit (via David Smith):
Apple’s libplatform is now OSS too with user-land os_unfair_lock (os/lock.c) in all its strict glory.
If you use it from Swift, you have to be careful, because it’s a struct and Swift doesn’t prevent you from copying or moving it around, which normally would be an error.
Previously: OSSpinLock Is Unsafe, Mutexes and Closure Capture in Swift.
Update (2023-01-27): David Smith:
A decade or so ago, “what lock should I use?” was a fairly complicated question on macOS/iOS.
2 Comments RSS · Twitter
From what I've seen in some crash reports, os_unfair_lock is not happy with forked processes.
e.g.
BUG IN CLIENT OF LIBPLATFORM: os_unfair_lock is corrupt.
Moving to posix_spawn seems to make it happier.