• 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: Running run loops in 10.6 (was: Need -[NSTask waitUntilExitOrTimeout:])
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Running run loops in 10.6 (was: Need -[NSTask waitUntilExitOrTimeout:])


  • Subject: Re: Running run loops in 10.6 (was: Need -[NSTask waitUntilExitOrTimeout:])
  • From: Ken Thomases <email@hidden>
  • Date: Sun, 20 Sep 2009 04:50:03 -0500

On Sep 20, 2009, at 1:38 AM, Jerry Krinock wrote:

Trying to find a way to "tickle" a run loop into returning in Mac OS 10.6, I wrote another little tool which, instead of spawning a short- duration NSTask, sends a message to a mach port which has been added to the current run loop. To my surprise, result is the same. Running in Mac OS 10.5, when the message is received, the run loop returns from runMode:beforeDate:. Running in Mac OS 10.6, it never returns.

+ (void)sendMessage:(NSTimer*)timer {
NSPort* receivePort = [timer userInfo] ;
NSPort* sendPort = [NSMachPort port] ;
NSData* data = [@"Hello" dataUsingEncoding:NSUTF8StringEncoding] ;
NSPortMessage* message = [[NSPortMessage alloc] initWithSendPort:sendPort
receivePort:receivePort
components: [NSArray arrayWithObject:data]] ;

You've got the send port and receive port mixed up here. The send port is the one you're sending to. The receive port is the one on which you'd receive any reply, if there is one.


Since the timer user info contains the port which was added to the run loop, you want to send to that one.

BOOL didSend = [message sendBeforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]] ;
NSLog(@"Sent message; %@.", didSend ? @"succeeded" : @"failed") ;
[message release] ;
}

Regards, Ken

_______________________________________________

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: Running run loops in 10.6 (was: Need -[NSTask waitUntilExitOrTimeout:])
      • From: Jerry Krinock <email@hidden>
References: 
 >NSTask is "Thread Unsafe". What does that mean? (From: Jerry Krinock <email@hidden>)
 >Re: NSTask is "Thread Unsafe". What does that mean? (From: "Adam R. Maxwell" <email@hidden>)
 >Need -[NSTask waitUntilExitOrTimeout:] (was NSTask "Thread Unsafe"...) (From: Jerry Krinock <email@hidden>)
 >Re: Need -[NSTask waitUntilExitOrTimeout:] (was NSTask "Thread Unsafe"...) (From: Chris Kane <email@hidden>)
 >Running run loops in 10.6 (was: Need -[NSTask waitUntilExitOrTimeout:]) (From: Jerry Krinock <email@hidden>)
 >Re: Running run loops in 10.6 (was: Need -[NSTask waitUntilExitOrTimeout:]) (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Subclassing NSUserDefaultsController
  • Next by Date: Re: Subclassing NSUserDefaultsController
  • Previous by thread: Re: Running run loops in 10.6 (was: Need -[NSTask waitUntilExitOrTimeout:])
  • Next by thread: Re: Running run loops in 10.6 (was: Need -[NSTask waitUntilExitOrTimeout:])
  • Index(es):
    • Date
    • Thread