>> 
>> 
>> 1) How can I interpret the call graph shown below? I'm finding it difficult 
>> to extract from that who's blocking whom.
>> 2) Is there something glaringly wrong with the strategy I sketched above? (I 
>> guess so, since it took a lot of experimentation to get it working at all.)
> 
> From your sample, I would judge that the main thread is waiting to acquire 
> the persistent store coordinator's lock. The worker thread is stuck trying to 
> deliver a message to the main thread, which it can't because the main thread 
> is currently tied up.
> 
> Now, you didn't explain too much what your background operations are doing. 
> Are they accessing any managed objects at all?

My managed objects have additional data caches which are properties on the 
NSManagedObject subclass but are not part of the core data model (is this a bad 
idea?). One of these data caches is an NSTextStorage which can be updated by 
text views. The background processes are extracting metadata from the string of 
the text storage. So I don't think this counts as accessing the managed object, 
does it? However, I do access another property on the managed object - an 
NSDate representing the time the text content was last edited. I use this in 
the background thread to help decide if it's necessary to update the metadata. 
I also access another boolean property which says if the managed object 
represents a text file. In principle, neither of these properties needs to be 
stored in the persistent store, and so don't need to be part of the core data 
model, but currently they are. Could/would just reading the values cause these 
issues?



> If so those managed objects ABSOLUTELY MUST come from a separate dedicated 
> context. You cannot access Core Data from multiple threads without using an 
> appropriate technique.

So to process the objects in the main managed context, I should create a new 
one, and copy the objects I want to process into this new context, then pass 
the new context to the background thread? Currently I'm just passing an array 
of managed objects. The context is never directly accessed in the background 
threads.

> 
> Also, I don't see any need for your completion block to use dispatch_sync. 
> Async should be fine here.

OK, I'll look at that.

Thanks!

Martin

>> 
>> -----------------------------------------------------
>> 
>> Call graph:
>>   2771 Thread_4677360   DispatchQueue_1: com.apple.main-thread  (serial)
>>   + 2771 start  (in TeXnicle) + 52  [0x1000018e4]
>>   +   2771 main  (in TeXnicle) + 34  [0x100001912]  main.m:32
>>   +     2771 NSApplicationMain  (in AppKit) + 869  [0x7fff829dfcb6]
>>   +       2771 -[NSApplication run]  (in AppKit) + 517  [0x7fff82a3b283]
>>   +         2771 -[NSApplication 
>> nextEventMatchingMask:untilDate:inMode:dequeue:]  (in AppKit) + 128  
>> [0x7fff82a43ed2]
>>   +           2771 _DPSNextEvent  (in AppKit) + 685  [0x7fff82a44613]
>>   +             2771 BlockUntilNextEventMatchingListInMode  (in HIToolbox) + 
>> 62  [0x7fff8a0e5cd3]
>>   +               2771 ReceiveNextEventCommon  (in HIToolbox) + 356  
>> [0x7fff8a0e5e42]
>>   +                 2771 RunCurrentEventLoopInMode  (in HIToolbox) + 209  
>> [0x7fff8a0e60a4]
>>   +                   2771 CFRunLoopRunSpecific  (in CoreFoundation) + 290  
>> [0x7fff81aaa6b2]
>>   +                     2771 __CFRunLoopRun  (in CoreFoundation) + 789  
>> [0x7fff81aaadc5]
>>   +                       2771 __CFRunLoopDoSources0  (in CoreFoundation) + 
>> 445  [0x7fff81a87aed]
>>   +                         2771 
>> __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__  (in 
>> CoreFoundation) + 17  [0x7fff81a88101]
>>   +                           2771 _performFileHandleSource  (in Foundation) 
>> + 1280  [0x7fff8a6dba7c]
>>   +                             2771 -[NSNotificationCenter 
>> postNotificationName:object:userInfo:]  (in Foundation) + 64  
>> [0x7fff8a61d846]
>>   +                               2771 _CFXNotificationPost  (in 
>> CoreFoundation) + 2554  [0x7fff81abb47a]
>>   +                                 2771 -[TPSyntaxChecker 
>> texOutputAvailable:]  (in TeXnicle) + 535  [0x10017daa7]  
>> TPSyntaxChecker.m:481
>>   +                                   2771 -[TPSyntaxChecker 
>> syntaxCheckerCheckDidFinish:]  (in TeXnicle) + 258  [0x10017e282]  
>> TPSyntaxChecker.m:518
>>   +                                     2771 -[TPFileEntityMetadata 
>> syntaxCheckerCheckDidFinish:]  (in TeXnicle) + 671  [0x1001975af]  
>> TPFileEntityMetadata.m:249
>>   +                                       2771 -[TPFileEntityMetadata 
>> postWarningsUpdateNotification]  (in TeXnicle) + 107  [0x1001971ab]  
>> TPFileEntityMetadata.m:225
>>   +                                         2771 -[NSNotificationCenter 
>> postNotificationName:object:userInfo:]  (in Foundation) + 64  
>> [0x7fff8a61d846]
>>   +                                           2771 _CFXNotificationPost  (in 
>> CoreFoundation) + 2554  [0x7fff81abb47a]
>>   +                                             2771 
>> -[TPWarningsViewController handleMetadataUpdate:]  (in TeXnicle) + 70  
>> [0x1001ab046]  TPWarningsViewController.m:91
>>   +                                               2771 
>> -[NSObject(NSThreadPerformAdditions) 
>> performSelectorOnMainThread:withObject:waitUntilDone:]  (in Foundation) + 
>> 131  [0x7fff8a6610c8]
>>   +                                                 2771 
>> -[NSObject(NSThreadPerformAdditions) 
>> performSelector:onThread:withObject:waitUntilDone:modes:]  (in Foundation) + 
>> 212  [0x7fff8a661220]
>>   +                                                   2771 
>> -[TPWarningsViewController updateUI]  (in TeXnicle) + 56  [0x1001ac408]  
>> TPWarningsViewController.m:235
>>   +                                                     2771 
>> -[TPWarningsViewController warningsViewlistOfFiles:]  (in TeXnicle) + 258  
>> [0x1001acf12]  TPWarningsViewController.m:297
>>   +                                                       2771 
>> -[TeXProjectDocument warningsViewlistOfFiles:]  (in TeXnicle) + 155  
>> [0x100022cdb]  TeXProjectDocument.m:4060
>>   +                                                         2771 
>> -[ProjectEntity items]  (in TeXnicle) + 311  [0x1000288b7]  
>> ProjectEntity.m:94
>>   +                                                           2771 
>> -[NSManagedObjectContext executeFetchRequest:error:]  (in CoreData) + 537  
>> [0x7fff8bcae309]
>>   +                                                             2771 
>> -[NSPersistentStoreCoordinator executeRequest:withContext:error:]  (in 
>> CoreData) + 1138  [0x7fff8bcafba2]
>>   +                                                               2771 
>> -[_PFLock lock]  (in CoreData) + 24  [0x7fff8bc9d548]
>>   +                                                                 2771 
>> pthread_mutex_lock  (in libsystem_c.dylib) + 536  [0x7fff824aad9d]
>>   +                                                                   2771 
>> __psynch_mutexwait  (in libsystem_kernel.dylib) + 10  [0x7fff8d1f0122]
>>   2771 Thread_4677447   DispatchQueue_2: com.apple.libdispatch-manager  
>> (serial)
>>   + 2771 _dispatch_mgr_thread  (in libdispatch.dylib) + 54  [0x7fff8031c9ee]
>>   +   2771 _dispatch_mgr_invoke  (in libdispatch.dylib) + 883  
>> [0x7fff8031cdea]
>>   +     2771 kevent  (in libsystem_kernel.dylib) + 10  [0x7fff8d1f0d16]
>>   2771 Thread_4677448   DispatchQueue_129: NSOperation low-priority 
>> concurrency-limiting queue  (concurrent)
>>   + 2771 start_wqthread  (in libsystem_c.dylib) + 13  [0x7fff82492171]
>>   +   2771 _pthread_wqthread  (in libsystem_c.dylib) + 404  [0x7fff824a7cab]
>>   +     2771 _dispatch_worker_thread2  (in libdispatch.dylib) + 304  
>> [0x7fff8031b1fa]
>>   +       2771 _dispatch_client_callout  (in libdispatch.dylib) + 8  
>> [0x7fff8031a0b6]
>>   +         2771 _dispatch_async_f_redirect_invoke  (in libdispatch.dylib) + 
>> 117  [0x7fff8031f317]
>>   +           2771 _dispatch_client_callout  (in libdispatch.dylib) + 8  
>> [0x7fff8031a0b6]
>>   +             2771 _dispatch_call_block_and_release  (in 
>> libdispatch.dylib) + 15  [0x7fff8031df01]
>>   +               2771 __103+[__NSOperationInternal 
>> _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke_0121
>>   (in Foundation) + 49  [0x7fff8a719700]
>>   +                 2771 __38-[TPFileEntityMetadata 
>> updateMetadata]_block_invoke_0  (in TeXnicle) + 92  [0x100196dac]  
>> TPFileEntityMetadata.m:168
>>   +                   2771 _dispatch_barrier_sync_f_slow  (in 
>> libdispatch.dylib) + 188  [0x7fff8031ea92]
>>   +                     2771 _dispatch_thread_semaphore_wait  (in 
>> libdispatch.dylib) + 16  [0x7fff8031ec32]
>>   +                       2771 semaphore_wait_trap  (in 
>> libsystem_kernel.dylib) + 10  [0x7fff8d1ee6c2]
>> 
>> 
>> 
>> 
>> _______________________________________________
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40mikeabdullah.net
>> 
>> This email sent to cocoa...@mikeabdullah.net
> 






_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to