-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lock-free LocationManager instantiation #352
Conversation
// since the access to locationManager might happen in | ||
// main thread after this function call but before | ||
// mainQueue async. | ||
dispatch_sync(dispatch_get_main_queue(), ^{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
theoretically this can deadlock as well. If you sync on background thread from the main one while background thread will call this method.
Not sure if it is possible scenario with this lib though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, you are right. Any ideas on how to fix that? 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this approach seem to work, take a look
Deadlock.zip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just not sure about run loop. it is not guaranteed to be available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is acceptable risk. My point is that sync
call from main thread to the background queue in not something common and should be generally avoided as a bad practice leading to the UI lags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for providing a workaround. It seems to have some overhead so I will avoid it at the moment. In case of any issues reports I will reconsider my position.
This PR address the deadlock issue.
Sometimes access to
MMELocationManager/locationManager
happens in the middle of the originallocationManager
getter. For example, code with access tolocationManager
can be scheduled for the next main RunLoop run, and then the getter would schedule its own internal initialization to the main queue and keep holding the@synchronized
lock. And on the next RunLoop run when an arbitrary access code would be called that lock would stop the main queue execution without a way to break the deadlock.Some extra context in the internal discussion.
Fixes https://mapbox.atlassian.net/browse/CORESDK-1440
Related: