Re: Where to declare/initialise an NSOperationQueue
Re: Where to declare/initialise an NSOperationQueue
- Subject: Re: Where to declare/initialise an NSOperationQueue
- From: Michael Ash <email@hidden>
- Date: Sat, 14 Feb 2009 11:36:57 -0500
On Sat, Feb 14, 2009 at 1:49 AM, Jacob Rhoden <email@hidden> wrote:
> Hi Guys,
>
> I have been starting to use NSOperationQueue. I have ended up with one put
> in each controller (ie see below), but now I have one in too many
> controllers. How does it work? Should I just have one global variable for
> the operation queue, or do multiple NSOperationQueue's "share" the same
> resources?
Yes, they all share the background worker threads that they use. The
incremental resource usage from having multiple NSOperationQueues in
your application is minimal. The only reason to have one versus many
is that you can control individual queues, for example by limiting the
number of simultaneous operations, or suspending/canceling/waiting for
the operations in the queue.
Unfortunately this resource sharing is buggy:
http://www.mikeash.com/?page=pyblog/dont-use-nsoperationqueue.html
If you read all the way to the end you'll see that NSOperationQueue
can be induced to crash even when using only *one* queue in the entire
program, so you can't save yourself by sharing a single global queue
as was once thought.
The bug manifests rarely enough that it can be useful for
experimentation but I would not plan to ship any code until the bug is
fixed. This may mean waiting for a Leopard point release or it may, in
the worst case, mean requiring Snow Leopard for your program. If you
plan to ship code in the near future I recommend avoiding
NSOperationQueue completely.
Mike
_______________________________________________
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