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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:01:15+00:00 2026-06-12T11:01:15+00:00

I’m currently on a (very) big application developed by something else. It’s well developed

  • 0

I’m currently on a (very) big application developed by something else.

It’s well developed and the code looks pretty good… Instead of the access to core data.

Indeed, each access to ManagedObjectContexts are made in several blocks, corresponding to several web services… in several threads.

And the documentation says it’s bad. That’s why sometimes, my app freeze on a Core Data access.

Yes, I know I should

Create a separate managed object context for each thread and share a single persistent store coordinator

as the doc says, but the code already exists and it’s very huge and my client need a solution quickly (as usual).

So here’s the question :

I’ve seen a [managedObjectContext lock] method. It seems to be some semaphore stuff. But the doc doesn’t speak a lot about.

My webservices, in different threads are using the same instance of the managedObjectContext.

-What do you think about doing

[managedObjectContext lock]
// core data access
// core data access
// core data access
[managedObjectContext unlock]

In each of my web services blocks ?
-Will this resolve the freezes ?
-Is it a recommended way ?

Nobody told me about the lock & unlock methods, so I made an EDIT :

Because de freezes do not occurs everytime, I tried 3 cases :

  • Do not protect my data access

  • Use [managedObjectContext lock] unlock] methods

  • Use @synchronized(managedObjectContext) { ... }

In the first case, a freeze occured 3 times on 10 tests. In the 2nd and 3rd cases, no freeze at all.

So my second question :

What is the difference using lock/unlock and @synchronize( ) ?

  • 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-12T11:01:16+00:00Added an answer on June 12, 2026 at 11:01 am

    I had a similiar problem, on existing code I didn’t work directly, with blocks performing fetch on a single managed object context, ended up on weird error, freezing, thread exiting etc.

    I solved by adding a sinchronize on context:

    NSBlockOperation *myBlock = [NSBlockOperation blockOperationWithBlock:^{
    
      // block operation
    
      @synchronized(managedObjectContext) {
    
        NSArray *result = [managedObjectContext performFetch:myFetch];
    
       // error management following
    
      }
    }];
    

    this is the quickest solution I found. I also tried to add some sort of locking condition but threads were messing up and deadlocking in some cases.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I

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.