开发者

Is NSFetchedResultController performFetch thread safe?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜