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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:43:32+00:00 2026-05-20T17:43:32+00:00

I need some guidance in how to debug problems with concurrency in Cocoa under

  • 0

I need some guidance in how to debug problems with concurrency in Cocoa under 10.6. I’m converting a ‘for’ loop to use NSOperations but most of the time, the code just freezes at some point through the loop. I can see NSLog output in the console to that effect. On the rare occasion, the code will run all the way through and it’s fine.

The code is model-layer only, initiated from a method in the controller. The method loops through just 8-10 model objects, instructing them to each write their output to a uniquely named file. 8 model objects = 8 separate files. There are no calls up to the GUI and the model objects are NSManagedObject subclasses, which contain a set of child NSManagedObject objects (0..n of them), which each owning object summarizes and writes out. The output format is JSON.

Code:

__block NSMutableArray *collectionOfCourses = [[NSMutableArray alloc] initWithCapacity:[[self courses] count]];

/* Create a filename.  Use our title and set it to lowercase */
NSURL *ourFileURL = [aURL URLByAppendingPathComponent:[[self title] lowercaseString]];
ourFileURL = [ourFileURL URLByAppendingPathExtension:@"js"];

for (Course *aCourse in [self courses]) {
       [[self opQueue] addOperationWithBlock:^{
       NSArray *arrayForOneCourse = [aCourse arrayAndWriteToFileURL:aURL fileFormat:format];
   [collectionOfCourses addObject:arrayForOneCourse];
    }];
}

I do a lot of NSLogs, would that be the issue? Is NSLog’ing from background threads a bad thing?

Since I’m adding to the mutable array from withinside a block, is it correct that I declare the mutable array as __block? I’ve tried it both ways and seemingly no difference relating to this freezing problem.

How do I debug this problem using Xcode v4? I want to know the line of code that it’s freezing on, or what two lines of code are executing at the same time and causing it to block the execution.. My former techniques of setting a single breakpoint and stepping through the code no longer work, because of the concurrency.

thanks

  • 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-20T17:43:33+00:00Added an answer on May 20, 2026 at 5:43 pm

    It’s nothing to do with your block-scoped variable. Your problem is that neither NSMutableArray nor NSManagedObject are in any way, shape or form thread-safe. You cannot do what you’re doing here. If you want to have this processed off the main thread, you need to use a dispatch queue or something similar to process each item serially (and even when you’re back on the main thread, you should use that same queue before you read from your mutable array. It’d probably be easier and safer, however, to do something like copy the mutable array to an immutable version when you’re finished and then dispatch a notification or call-back to the main thread with the new, immutable copy embedded.

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

Sidebar

Related Questions

I need some info on how to use margins and how exactly padding works.
Need some guidance on how to go about unit testing a shopping cart (.net
Need some guidance and ideally some first-hand experience. We committed to a php framework
Need some guidance figuring out what went wrong. I've been using mysql, phpmyadmin for
Need some guidance. I have java webstart app and I want it to connect
I need some guidance on how to save video data to core data so
I need some guidance with this issue I have. I have a navigational Controller,
I need some advice as to how I easily can separate test runs for
I need some software to explore and modify some SQLite databases. Does anything similar
I need some help from the shell-script gurus out there. I have a .txt

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.