CLLocationManager uses @synchronized(self) internally
| Originator: | demid.itsk | ||
| Number: | rdar://33132086 | Date Originated: | July 5th 2017 |
| Status: | Resolved: | ||
| Product: | Core Location | Product Version: | iOS 8 / 9 / 10 |
| Classification: | Bug | Reproducible: | Always |
Area: Core Location Summary: It seems that CLLocationManager uses @synchronized(self) internally. It makes it dangerous using CLLocationManager instances in @synchronized blocks in developers' code, since it is not clear that the code may lock. It may result in freezes and even a deadlock (that's what I ran into). The danger is that it looks like it works, and the code looks perfectly sane. And when it happens, it's really hard to figure out the reason, especially if the threading logic is complicated. Steps to Reproduce: 1) Create a CLLocationManager instance. 2) On a background thread run a long-running task inside a @synchronized(self.locationManager) block. 3) On the main thread call [locationManager stopUpdatingLocation]. Probably, some of the other methods would work as well, it's just the only method I tried. Here is an example project demonstrating the issue: https://github.com/DMAPro/LocationManagerDeadlock (also attached to this report) Expected Results: The main thread and the background thread work independently Observed Results: The main thread (and the UI) freezes, until the background thread completes the task Version: Tested on iOS 8 / 9 / 10 (including the latest public release 10.3.2 14F89) on iPhone (both device & simulator). Didn't test on an iPad. Notes: Configuration:
Comments
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!