Re: Messages between Threads
Re: Messages between Threads
- Subject: Re: Messages between Threads
- From: "Paul Sanders" <email@hidden>
- Date: Sat, 14 Mar 2009 17:29:31 -0000
> So: what should be done?
1. Do the calculations in a sub-thread.
2. Test a 'please stop' variable each time round the loop in that thread.
3. Set this variable in the main thread when the user clicks the Stop
button.
4. To show progress, call performSelectorOnMainThread from the sub-thread.
Do this every, say, 1000 loop iterations for efficiency. That method (so to
speak) is safe. I'm not sure if other techniques are safe or not, but my
guess is that they aren't.
The 'please stop' variable can be in a class object accessible to both
threads, and can be accessed via getter and setter methods (which of course
are each being called by a different thread) if you so choose. Just be sure
you have a reasonable grasp of the sort of issues doing this can involve
before you write your code. It is important, for example, that any objects
the sub-thread might access do not go away until the thread has terminated.
http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.html
_______________________________________________
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