I'm working with NSManagedObjectContext in mul开发者_运维技巧tithreads. I wonder if it request lock before call NSFetchedResultController performFetch.
Shall I do this
[moc lock];
NSError *error = nil;
if (![fetchedResultsController_ performFetch:&error]) {
//TODO: add fetch error handler
}
[moc unlock];
Or just
NSError *error = nil;
if (![fetchedResultsController_ performFetch:&error]) {
//TODO: add fetch error handler
}
If your fetchedResultsController
is shared across multiple threads, then not only must you lock the managed object context before performing the fetch, but it must also be locked while you use any object returned by that fetch. Naturally, that's not a very easy thing to guarantee, and tends to limit the benefits of doing things on mulitple threads in the first place.
Applications using Core Data are strongly encouraged to use one managed object context per thread. See Concurrency with Core Data for more information.
精彩评论