This line of code is being called in my awakeFromFetch
method located inside a custom managed object which implements NSManagedObject
. This line in particular is making a call to my singleton network manager class called sharedManager
.
[self setSync:(![[WKNetworkManager sharedManager] objectHasPendingRequests:self.objectID]) ];
The dispatch_once block will be hit as is shown below. Notice that it is implemented in a good way as is shown here:
The dispatch_once call then goes to once.h and here it freezes right on the highlighted line:
Here is the stack trace:
All of this happens when trying to load a previously saved network queue file. The application is closed fully to save, and then launched again and then this freezing/locking occurs.
I even tried to use this code instead to solve the problem as is suggested here, and it did not work. But changing this would probably not matter anyway, as my original dispatch_once code has been working just fine for a long time. It's just in this particular case.
if ([NSThread isMainThread])
{
dispatch_once(&onceToken, ^{
stack = [[KACoreDataStack alloc] init];});
}
else
{
dispatch_sync(dispatch_get_main_queue(), ^{
dispatch_once(&onceToken, ^{
stack = [[KACoreDataStack alloc] init];});
});
}
So far, these are my sources for troubleshooting this type of problem:
- Code execution stops on using thread safe Singleton initialization code
- http://cocoasamurai.blogspot.jp/2011/04/singletons-your-doing-them-wrong.html
- http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial
- ios singleton class crashes my app
- http://benalpert.com/2014/04/02/dispatch-once-initialization-on-the-main-thread.html
- http://www.bignerdranch.com/blog/dispatch_once-upon-a-time/
Thanks for your help!