• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Messages between Threads
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Messages between Threads
      • From: Michael Ash <email@hidden>
References: 
 >Messages between Threads (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: NSProgressIndicator's setUsesThreadedAnimation only works sometimes?
  • Next by Date: Re: Calling Script Objects in Applescript
  • Previous by thread: Messages between Threads
  • Next by thread: Re: Messages between Threads
  • Index(es):
    • Date
    • Thread