Re: NSInvocationOperations and background Threads
Re: NSInvocationOperations and background Threads
- Subject: Re: NSInvocationOperations and background Threads
- From: John Love <email@hidden>
- Date: Mon, 19 Oct 2009 07:45:11 -0400
Big thank you's to Ken Thomases, Nick Zitzmann and Quincey Morris
(can't seem to find Quincey's email?)
Found my stupid mistake .. stupid because you guys individually
mentioned it time and time again. Namely, my -startBgThread begins in
the main Thread. So when I call -startOperation to add my Operation
to the Queue (which starts up the background thread "sometime", and I
really don't care when!), I should end -startBgThread. Stop doing
further stuff in the main Thread, right then-and-there. Let the
background Thread cancel the Operation if need-be, and if so, send a
Notification back to the main Thread.
Anyway, my bad!
John
=====
On Oct 18, 09, at 5:31 PM, Ken Thomases wrote:
On Oct 18, 2009, at 7:26 AM, John Love wrote:
Thanks for your prompt reply, I really appreciate it.
You're welcome.
I have revamped my code to have just one NSInvocationOperation
whose selector contains the long for-loop. [...] the long for-loop
is within -doAllOperations.
OK, as far it goes.
It's my understanding from the docs and other Cocoa mailing list
readers that when -addOperation: is called, a new background Thread
is started up.
Well, you should stop trying to think about when exactly threads are
started up (or how many there are, or how long they run, or exactly
which one your operations run on, etc.). All of that is
implementation detail about which you shouldn't care. The only
important thing is that your (non-concurrent) operations will be run
on some background thread that you are not responsible for setting
up or managing. (If you implement concurrent operations, you still
aren't guaranteed anything about on which thread your -start method
is invoked, but you take responsibility for the execution context
after that.)
If that is true, then my long for-loop should be executing in the
background Thread. If I'm still on-track, then I have a problem in
that I temporarily placed a NSLog() call within my -doCalculation,
but nothing gets printed in my log. So, for the moment I am lost.
Well, there's no way for me to provide additional insight without
seeing your code. If you suspect your code is blocked, you can
sample your process (e.g. using Activity Monitor or the "sample"
tool), which can show you where your threads are spending their
time. You can also put may more logging statements throughout your
code to track its progress. You can break into your program in the
debugger and examine the various threads. Etc.
Regards,
Ken
John Love
Touch the Future! Teach!
_______________________________________________
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