Re: Migrating changed objects between contexts
Re: Migrating changed objects between contexts
- Subject: Re: Migrating changed objects between contexts
- From: Keary Suska <email@hidden>
- Date: Wed, 2 Dec 2009 09:28:37 -0700
On Dec 1, 2009, at 11:05 PM, Jim Thomason wrote:
> So. First off, is there some way I can just leave the existing code in
> there that uses the same context and just locks it in the secondary
> thread? The second thread basically consisted of:
>
> -(void) makeGraph {
> NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
> [[document managedObjectContext] lock];
> //big honkin' code to make the graph
> [[document managedObjectContext] unlock];
> [pool release];
> }
>
> But since both the second thread and the main thread were trying to
> load up the same object at once, it deadlocked. Is there some other
> bit of locking magic I can add in to do it?
It shouldn't deadlock. The doc for -lock says: "If you lock (or successfully tryLock) a managed object context, the thread in which the lock call is made must have a retain until it invokes unlock. If you do not properly retain a context in a multi-threaded environment, this will result in deadlock." Did you heed it?
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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