Handling NSManagedObjectContextDidSaveNotification from different threads
Handling NSManagedObjectContextDidSaveNotification from different threads
- Subject: Handling NSManagedObjectContextDidSaveNotification from different threads
- From: Rick Mann <email@hidden>
- Date: Tue, 10 Aug 2010 13:55:18 -0700
We have an app that uses a "main" NSManagedObjectContext (MOC) for all UI-related work, and has background threads that add and update data via their own dedicated MOCs. When they call -save: on their MOC, the "main" MOC gets the NSManagedObjectContextDidSaveNotification and calls -mergeChangesFromContextDidSaveNotification:.
The problem is, this actually happens on the thread that called -save:, not on the main thread. We're seeing occasional crashes, and suspect that it is due to this problem. However, I didn't see anything in the docs that said we had to call -save: from the main thread, or take any special steps when handling that notification.
Did I just overlook something, or should this work safely always? It seems like the latter is unlikely, since two threads could be accessing a MOC simultaneously.
Thanks,
Rick
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden