Re: NSOperation NSOperationQueue
Re: NSOperation NSOperationQueue
- Subject: Re: NSOperation NSOperationQueue
- From: Sandro Noel <email@hidden>
- Date: Wed, 24 Sep 2008 12:26:00 -0400
Shawn.
Very clear, thank you !!!!
Sandro.
On 24-Sep-08, at 12:18 PM, Shawn Erickson wrote:
On Wed, Sep 24, 2008 at 8:56 AM, Sandro Noel <email@hidden>
wrote:
Greetings.
I need a clarification about the NSOpration ans NSOperationQueue
I read in the documentation that the NSOperation itself is non
concurrent.
and that i can program it to be, if I override this and that
method. and
configure the runtime env.
I assume that means create my own threads(NSTasks).
I am not sure if the last sentence above shows some confusion on
thread and task or was just noting either could be used but just in
case...
NSTasks are processes each of which may have one or more threads.
NSThreads are threads each of which has a thread stack, thread
context, etc.
A "concurrent" operation is called from the "managing" thread of the
operation queue and it is left up to the operation on how it wants to
execute its operation. For example it could do the computation
directly when main is called but that would prevent the operation
queue from moving on to another operation (likely defeats the purpose
of using a queue and run contrary to the intent of returning true to
isConcurrent). Or it could startup a thread or task to do the
operation or fire off an async request, etc (more inline with the
intent of isConcurrent) and return back to the operation queue
(allowing it to move onto the next operation).
A "non-concurrent" operation is called by a worker thread that the
operation queue manages. This operation will then run in this worker
thread and the operation queue can move onto other operations (since
the operation queue managing thread isn't blocked).
It basically means does the operation manage its own concurrency
(isConcurrent = YES) or does the operation queue need to do it for the
operation (isConcurrent = NO).
If I use NSOperation, override only the main method, I get a non
concurrent
object to run a particular piece of code.
Stack these lovely objects in an operationQueue and set
setMaxConcurrentOperationCount to 4.
The Queue itself is the one managing the concurrency. and I will
have 4
operations runing at the same time?
Correct.... assuming your operations don't state dependencies that
prevent concurrency, the system has the ability to execute 4 threads
(enough physical or virtual "cores", aka hyper threading) and current
system pressure doesn't prevent reaching max concurrency.
-Shawn
_______________________________________________
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