Update 2: I found a workaround which is to synchronize MOC deallocating and saving. Please see the updated project. https://github.com/shuningzhou/MOCDeadLock.git
Note: I made it fail more aggressively. Don't run it on a real device!
Update: A sample project to demonstrate this issue. https://github.com/shuningzhou/MOCDeadLock.git
XCode 6.2: Unable to reproduce.
XCode 6.3: Reproducible.
XCode 6.4 beta: Reproducible.
========================== The Issue ===============================
Our app randomly stuck on OSSpinLockLockSlow
after upgrading to XCode 6.3. In our project, we used NSOperation
and NSOperationQueue
to fetch data from our server and used Core Data for data persistence.
This issue never happened before! You can see from the stack trace that no calls are made by our code. I am not sure where to start debugging this. Could someone provide some guidance?
Thank you in advance!
Please see the stack trace
Edit:
We are using AFNetworking
and our NSOperations
are subclasses of AFHTTPRequestOperation
. We added some custom properties and overrode the method -(void)start
:
- (void)start;
{
//unrelated code...
NSString *completionQueueID = [NSString uuid];
const char *cString = [completionQueueID cStringUsingEncoding:NSASCIIStringEncoding];
self.completionQueue = dispatch_queue_create(cString, DISPATCH_QUEUE_SERIAL);
//unrelated code....
[super start];
}
For Core Data
, We are following the thread-confinement
pattern. We have separate managed object context
for each thread, and the contexts share a static persistent store coordinator
.
Edit 2:
More info: I found that this issue happens when the system exits multiple threads at the same time. We store the Managed Object Context in the thread dictionary, and they get released when the threads exit.
[[[NSThread currentThread] threadDictionary] setObject:dataManager forKey:@"IHDataManager"];
CPU usage is around 20%.
NSOperation
. – Showiness_sigtramp
. (Note that you can copy stack traces with Cmd-C; you don't have to take screenshots.) I assume that your CPU usage becomes very high (maybe turns the fans on)? – Balikpapan