OSSpinLock lies, no safe spinlock available to third parties on iOS

Number:rdar://23896366 Date Originated:12/14/2015
Status:Open Resolved:
Product:iOS SDK Product Version:
Classification:Serious Bug Reproducible:
According to John McCall, spinlocks are illegal on iOS because iOS does not guarantee progress in the face of priority inversion. Greg Parker says there is a spinlock algorithm that works but requires a full word of storage. OSSpinLock is an int32_t, and is documented as being "immune to most priority-inversion livelocks", but when asked, Greg Parker says that OSSpinLock is not safe on iOS (unless all users have the same priority).


This comes as a surprise, because it's documented as being safe, and there's no other spinlock provided by the system. I've written code using spinlocks that use OSSpinLock under the assumption that it's safe, and I assume plenty of other people have done this too.

To that end, there really should be a spinlock implementation that's safe to use on iOS and is provided on the system and made available to third-party devs. By not providing such an implementation, third-party software will continue to use spinlocks that aren't safe (and for that matter I bet there's a fair amount of first-party software that's using OSSpinLock).


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!