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 8439193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:56:31+00:00 2026-06-10T07:56:31+00:00

What is more suitable for a situation where data needs to be stored in

  • 0

What is more suitable for a situation where data needs to be stored in Core-Data on one thread and read from Core-Data on another?

I was thinking of GCD but how does it work with the creation of the NSManagedObjectContext for each thread? How does one create these objects in a queue?

The data store needs to be updated/synced when changes have been made on various threads, is this better to do with GCD or NSOperation?

I would like to be able to just pass blocks to the 2 queues when reading and writing to the data store as needed, without having issues with corrupting the store or having different versions of the store.

  • 1 1 Answer
  • 0 Views
  • 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-06-10T07:56:33+00:00Added an answer on June 10, 2026 at 7:56 am

    The debate between GCD and NSOperation basically boils down to the argument of using the highest level of abstraction that provides you with a good solution.

    NSOperationQueue is built on top of GCD, so it must be a higher level of abstraction.

    However, GCD is so easy to use in the general case, that I find it is preferable to NSOperationQueue in many cases.

    Now, when you bring CoreData into the mix, I would suggest a third alternative. If you are using iOS 5, then you can use private queue concurrency with your MOC. I find that is a good abstraction, and provides an easy to use interface.

    So, I would suggest you simply create a MOC with NSPrivateQueueConcurrencyType for each thread in which you want to do Core Data. You can choose, based on your application characteristics, whether to share a persistentStoreCoordinator, or use a separate one. You could even use nested contexts (with a caveat for the insert-side).

    Basically, it follows this model…

    NSManagedObjectContext *moc = [[NSManagedObjectCotext alloc] initWithConcurrencyType:NSPrivateQueuqConcurrencyType];
    moc.parentContext = contextIWantToBeParent;
    moc.persistentStoreCoordinator = pscIWant;
    
    [moc performBlock:^{
        // Your MOC stuff running on its own private queue
    }];
    

    Of course, you must choose one method (either parenting to an existing MOC or attaching to a PSC).

    I generally prefer the performBlock method.

    EDIT

    Thanks. I read that NSManagedObject isnt thread safe. How would I
    create new NSManagedObjects on that private queue? – Helium3

    Yes, that is true. However, when you create a MOC with a concurrency type, you are agreeing to a contract that goes something like this.

    I, an astute programmer, do solemnly agree to the following Core Data Rules regarding concurrency:

    1. If I use NSConfinementConcurrencyType, I will only use it while running on the thread that created it.

    2. If I use NSPrivateQueueConcurrencyType, I will only use the MOC from within either performBlock or performBlockAndWait.

    3. If I use NSMainQueueConcurrencyType, I will only use the MOC from within either performBlock, performBlockAndWait, or when I know that I am running on the main thread.

    If you follow those rules, then you will be able to use the MOC on other threads.

    Specifically, when using performBlock, the Core Data API will make sure the code is appropriately synchronized.

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

Sidebar

Related Questions

Which one of these would be more suitable for RLE on bytes? I need
Hi i want to read and write data from CSV and excel file both.Can
In Asp.Net, what control is more suitable for getting time (hh:mm) from user and
I often hear about other languages promoted as being more suitable for multi-core/concurrent programming
More than one time I have encountered the following problem when building code with
More specifically, is List(T)(IEnumerable(T)) thread-safe if the IEnumerable used to initialize the list is
I heard that WPF is more suitable than WinForms for working with WCF. Is
I don't know if this actually belongs here, maybe this question is more suitable
i've got one more question today are there any html parsers with not strict
I want to play youtube videos in my application.I get this data from gdata.youtube.com

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.