Re: Need some advice on multithreading
Re: Need some advice on multithreading
- Subject: Re: Need some advice on multithreading
- From: Peter N Lewis <email@hidden>
- Date: Thu, 27 Nov 2008 14:04:57 +0900
At 9:00 -0800 26/11/08, David Phillip Oster wrote:
However, if instead of using 10 NSOperationQueues, you use a single
global NSOperationQueue, the program stops crashing and becomes
reliable.
If you want serialization, then use -[NSOperation addDependency:]
that is what addDependency: is for.
Since the whole point of NSOperationQueue is to balance the mapping
from cores to threads over the whole machine to get the best
throughput for the end-user, for the end-user's mix of processes, it
makes sense that Apple intended you to have a single
NSOperationQueue per process.
This is an interesting observation, and you appear to be correct, I
can't duplicate the crash using a single NSOperationQueue, so now we
have the theory:
NSOperationQueue is safe if and only if
* You use addOperation on only the main thread (or possibly on only one thread)
or
* You have only a single NSOperationQueue
or
* You have only a single processor core
However, there is no way to guarantee any of these conditions in your
code (even if they are sufficient) since you can't control the number
of cores, and you can't guarantee that some other code in your
application is not going to use NSOperationThread (for example, what
if some part of Cocoa starts using NSOperationQueue, or some third
party library you use uses it internally, or your work mate creates a
new feature and uses his own NSOperationQueue).
Now if NSOperationQueue was actually a singleton, that would be
different, but it isn't.
What a mess. What's needed is for Apple to fix this in an update for
Leopard, or for someone to write a drop in replacement for
NSOperationQueue, even if it simplifies the options a bit, so that at
least e can point people to an alternative that is less onerous than
"go learn NSThreads".
Peter.
--
Keyboard Maestro 3 Now Available!
Now With Status Menu triggers!
Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/> <http://download.stairways.com/>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden