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

  • Home
  • SEARCH
  • 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 6561619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:36:37+00:00 2026-05-25T13:36:37+00:00

Ok, so I have multiple threads pull data from the persistent store (SQLite database)

  • 0

Ok, so I have multiple threads pull data from the persistent store (SQLite database) into a single NSManagedObjectContext (MOC) instance. I have tested it pretty thoroughly and in the case where operations overlap (thread 4 loads into the MOC while thread 5 does so too), everything runs smoothly.

I have read (most of) the Core Data Programming guide and am aware that Apple does not condone this behavior, but I am wondering what the particular reasons are. In the docs Apple briefly alludes to the fact that not only writes are dangerous, but reads are as well because faulting may occur. How (if all the objects I load from the separate threads are individual entities with no overlap with each other)? And doesn’t that just mean that the app will take a performance hit? So if I determine that a performance hit is a better tradeoff than increased memory usage, I would be inclined to use the one MOC (non-recommended) method.

I am going to revert to the recommended method in any-case but am just curious about the specific details of what could happen if these rules aren’t adhered to. Thanks in advance.

  • 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-05-25T13:36:37+00:00Added an answer on May 25, 2026 at 1:36 pm

    I don’t really know, but since nobody answered yet.

    Not thread-safe is not thread-safe. Imagine the Core Data programmers put some unexposed instance variable in NSManagedObjectContext numberOfObjectsLoaded. In thread A, you access a relationship of a managed object, foo.bar. In thread B, you make a change to some completely unrelated object baz.number = 14. Both foo and baz are faults. They get loaded. Both threads try to execute the line of code

    numberOfObjectsLoaded += 1
    

    But thread A reads numberOfObjectsLoaded, gets 77, then context switch. Thread B reads 77 also, adds 1, assigns 78. Back to thread A. It adds 1 to 77, which is what it read, gets 78, and also assigns 78 to numberOfObjectsLoaded. numberOfObjectsLoaded should have 79, but has 78. That inconsistency will lead to unexpected errors, and probably eventually a crash. It will only happen maybe 1/1000 times you run your program, and possibly nothing bad will be apparent until several minutes after the actual error occurred. Very hard to debug.

    Follow their advice and don’t try it.

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

Sidebar

Related Questions

Basically i have multi threads that adds data into a queue via SQLite. I
I have multiple threads which are serializing my 'Data' objects to files. The filename
I am required to have multiple threads writing to a single buffer (contiguous chunk
Can Node JS have multiple threads serving HTTP clients on a single HTTP port?
I have multiple threads that are processing rows from the same table that is
I have a Java JDBC application that uses multiple threads to retrieve information from
I'm running into an issue where I have multiple threads that write to the
I have multiple threads (C# application running on IIS) running that all need to
I have multiple threads who all need to write to the same Dictionary. I
I have a scenario where I have multiple threads adding to a queue and

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.