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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:29:55+00:00 2026-05-23T11:29:55+00:00

Apple Threading guide says: For multithreaded applications, Cocoa frameworks use locks and other forms

  • 0

Apple Threading guide says:

For multithreaded applications, Cocoa frameworks use locks and other forms of internal synchronization to ensure they behave correctly. To prevent these locks from degrading performance in the single-threaded case, however, Cocoa does not create them until the application spawns its first new thread using the NSThread class. If you spawn threads using only POSIX thread routines, Cocoa does not receive the notifications it needs to know that your application is now multithreaded. When that happens, operations involving the Cocoa frameworks may destabilize or crash your application.

To let Cocoa know that you intend to use multiple threads, all you have to do is spawn a single thread using the NSThread class and let that thread immediately exit. Your thread entry point need not do anything. Just the act of spawning a thread using NSThread is enough to ensure that the locks needed by the Cocoa frameworks are put in place.

In my iOS app, I’m starting several pthreads from C++ code right from the start. To be sure the app behaves right, according to the doc above, I create a fake NSThread that does nothing. I don’t like creating such useless code (usually it’s WTF, when you first read it) and I want to avoid doing so. Is there any better way to put my app into multithreaded mode?

  • 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-23T11:29:56+00:00Added an answer on May 23, 2026 at 11:29 am

    If there is, it’s not public and might be unstable.

    If you’re hitting a WTF in your code, rename and rejigger things so that it makes sense. Since you need a dummy object with a dummy selector as well, you could just add a throwaway class like CocoaMultithreading and then send it a +beginMultithreading message:

    @interface CocoaMultithreading : NSObject
    + (void)beginMultithreading;
    @end
    
    int
    main(void) {
        [CocoaMultithreading beginMultithreading];
        /* now do whatever you want */
        return EXIT_SUCCESS;
    }
    
    @implementation CocoaMultithreading
    + (void)dummyThread:(id)unused
    {
        (void)unused;
    }
    
    + (void)beginMultithreading
    {
        [NSThread detachNewThreadSelector:@selector(dummyThread:)
                toTarget:self withObject:nil];
    }
    @end
    

    That should be explicit enough.

    ETA: Alexander Staubo points out that, since OS X 10.5/iOS 2.0, you can call the -start method on an NSThread directly, so the very simplest way to flip on Cocoa multithreading would be this:

    void XXXActivateCocoaMultithreading(void) { [[NSThread new] start]; }
    

    Then, in your main function:

    XXXActivateCocoaMultithreading();
    

    That is explicit, as well, but far less messy. (The XXX is there to remind you to prefix non-static functions. Since static functions often become non-static at some point, prefixing them all from the start is a good move.)

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

Sidebar

Related Questions

I used to think I was a reasonably intelligent person. apple's threading programming guide,
Apple's Threading Programming Guide states that: Although good for occasional communication between threads, you
Apple HIG says I must include a 512x512 and a 29x29 icons along with
Apple says: removeFromSuperview Unlinks the receiver from its superview and its window, and removes
Apple's Documentation mentions that threading the quartzcore rendering of PDF's must be manually handled.
Okay, I've read a number of other posts on StackOverflow regarding multi-threading, but I
Apple strongly recommends using the binary plist format when reading large XML-based data sets
Apple describes the architectural pattern used by iPhone apps as MVC. However, virtually no
Apple really had bad documentation about how the provider connects and communicates to their
Apple wants me to give the user a friendly apology if I can't find

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.