• 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: Where to send different messages while RunLoop is running
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Where to send different messages while RunLoop is running


  • Subject: Re: Where to send different messages while RunLoop is running
  • From: John Love <email@hidden>
  • Date: Sun, 11 Oct 2009 16:45:54 -0400

Wow, your response was super prompt and I thank you for that.

I have used a thread (and -performSelectorOnMainThread) and this approach definitely works. Having said that, I am in the process of just learning about NSMachPorts and am doing this now. I just wish to use 2 NSMachPorts to communicate back and forth between the main and secondary Threads

You said "it seems inappropriate for it(-shouldExit) to do things unrelated to testing whether or not the thread should exit". I will definitely work on that because I think you're correct.

I definitely do agree that polling is sporadic or unpredictable -- and taking your clue about +distantFuture to heart, I changed it to +date to indicate now, or immediately -- and it now works even with - shouldExit sending other message IDs. I just need to think where to send these other message IDs per your recommendation.

=====

On Oct 11, 09, at 4:00 PM, Alastair Houghton wrote:

On 11 Oct 2009, at 20:40, John Love wrote:

Reference:

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html#//apple_ref/doc/uid/10000057i-CH16-SW29

As noted, Apple's sample code sends a kCheckinMessage back to the main Thread and then monitors the currentRunLoop until -shouldExit returns YES. Within -shouldExit, I wish to monitor error conditions (e.g., a external application's document not open). If such an error exists, send a unique error message ID and then return NO when -shouldExit is finished.

Is -shouldExit the appropriate place for sending these other message IDs?

Not really, no. Why should a method called -shouldExit do such a thing? It is, obviously, up to you what -shouldExit does (since it's a method defined by MyWorkerClass, which is entirely your business), but it seems inappropriate for it to do things unrelated to testing whether or not the thread should exit.


Also, there's no guarantee that the run loop will return regularly, unless you set some other date besides +distantFuture... As an aside, however, polling is *really ugly* and wastes both energy and CPU time, so ideally if you can avoid it then you should; whether this is possible depends on the tests you need to do.

FWIW, it seems like quite a complicated design using this Mach port sample as a basis for the kind of thing you're proposing. How are you proposing to do your checks, precisely? Why not just use a thread and -performSelectorOnMainThread:?

Kind regards,

Alastair.

--
http://alastairs-place.net




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


  • Follow-Ups:
    • Re: Where to send different messages while RunLoop is running
      • From: Alastair Houghton <email@hidden>
References: 
 >Where to send different messages while RunLoop is running (From: John Love <email@hidden>)
 >Re: Where to send different messages while RunLoop is running (From: Alastair Houghton <email@hidden>)

  • Prev by Date: Creating NSMatrix of NSImageCells
  • Next by Date: Re: Screensaver won't run on 10.6 even after porting to 64-bit
  • Previous by thread: Re: Where to send different messages while RunLoop is running
  • Next by thread: Re: Where to send different messages while RunLoop is running
  • Index(es):
    • Date
    • Thread