Open hamzasohail opened 2 years ago
We do wait on a mutex where possible. There's two scenarios where we don't:
Hmmm, if you look at this report here, you seem to be causing an inversion which the app developer doesn't have a way to avoid. I'd suggest looking at ways to avoid such inversions. At the end of the day, the users of the app may see UI responsiveness issues because of them.
https://github.com/realm/realm-core/pull/5799 doesn't fully fix this, but it will eliminate the most common case where the main thread waits on a condition variable rather than a mutex.
@tgoyne @hamzasohail can this be closed?
No, this is still a problem.
There was a report from a user who observed a "Hang Risk" runtime issue in Xcode when running their app when using the Realm SDK.
https://www.mongodb.com/community/forums/t/hang-risk-thread-warning-on-xcode/177869
There is explicit guidance by Apple about the risk associated with this primitive. Upon examination, it seems realm implements mutexes (realm-core/src/realm/util/interpocess_mutex.cpp) with dispatch semaphores. This is risky -- dispatch semaphores do not provide priority inversion avoidance since the system doesn't know which thread will eventually signal the waiting thread.
Instead, I propose that for mutexes (and other locking primitives you provide), you should use OS unfair locks instead which provide priority inversion avoidance (this explicit guidance is available in this talk: https://developer.apple.com/videos/play/wwdc2017/706/)