Is there any way to enter Cocoa multithreaded mode without creating fake NSThread?

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?

6
задан fspirit 6 May 2011 в 08:25
поделиться