Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 721919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:55:44+00:00 2026-05-14T05:55:44+00:00

My application downloads and caches photos into coreData in background threads while still allowing

  • 0

My application downloads and caches photos into coreData in background threads while still allowing the user to poke around in the application. Currently after a photo’s data is done downloading I start a thread to save it to coredata using the suggested shared storeCoordinator and thread-owned context then merge on the main thread, I also lock the shared coordinator until just before merging. This locking causes performance issues though on reads by the user.

Do I need to lock here? What are the pitfalls of not locking? The flow is essentially:

-(void)saveThreaded:(args)args {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSThread setThreadPriority:.5];

[_appDelegate.persistentStoreCoordinator lock];  //necessary?
NSManagedObjectContext *_moc = [[NSManagedObjectContext alloc] init];
[_moc setPersistentStoreCoordinator: [_appDelegate persistentStoreCoordinator]];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(threadControllerContextDidSave:)
                                             name:NSManagedObjectContextDidSaveNotification object:_moc];
...<blah blah>...
}

- (void)threadControllerContextDidSave:(NSNotification*)saveNotification {
// need to unlock before we let main thread merge  
[_appDelegate.persistentStoreCoordinator unlock];
[self performSelectorOnMainThread:@selector(mergeToMainContext:) withObject:saveNotification waitUntilDone:YES];
}

- (void)mergeToMainContext:(NSNotification*)saveNotification {
NSError *error;
[_appDelegate.managedObjectContext mergeChangesFromContextDidSaveNotification:saveNotification];  
if (![_appDelegate.managedObjectContext save:&error]) {
<handle error>
}
}
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:55:45+00:00Added an answer on May 14, 2026 at 5:55 am

    No you do not need a lock here, the NSManagedObjectContext will lock the NSPersistentStoreCoordinator and you are probably hindering that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a paid application on the App Store, which when a user downloads,
I have a wpf xbap application that downloads some data in background. There is
I have an application that downloads information from a web service and caches it
Our application downloads data from the internet using RSS but is having connection problems
My iPhone application downloads large files from the internet (videos, for instance). I'd like
I've got an application that downloads data from a 3rd party at 3am every
I am building a Monotouch application which downloads data from the server encrypted using
My MVC application has a simple file download controller action that downloads a file.
My .NET WinForms application connects to ftp server and downloads a file. To do
For one of the user is not able to download application from Android Play

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.