• 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: Adding a Timer to a Thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding a Timer to a Thread


  • Subject: Re: Adding a Timer to a Thread
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Tue, 26 May 2009 20:27:20 +0200


Le 26 mai 09 à 20:15, Andreas Grosam a écrit :


What would you suggest is the preferred way to add a timer to a different running thread?



Normally, I would use:

   NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
   [runLoop addTimer:aTimer forMode:NSDefaultRunLoopMode];


However, this requires that it will be invoked from the context of the target thread. How do I get the runLoop for any other than the current thread?

NSRunLoop is not thread safe, so you don't get it. Even is it was possible, you would not be able to use it.


That said, CFRunLoop is thread safe.

You can retrieve it using - performSelector:onThread:withObject:waitUntilDone:modes passing a mutable object as argument (an MutableArray for example) which will be used to store the return value (your CFRunLoop).

- (void)retrieveCurrentRunLoop:(NSMutableArray *)array {
	[array addObject:(id)CFRunLoopGetCurrent()];
}

_______________________________________________

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: Adding a Timer to a Thread
      • From: Ken Thomases <email@hidden>
References: 
 >Adding a Timer to a Thread (From: Andreas Grosam <email@hidden>)

  • Prev by Date: Adding a Timer to a Thread
  • Next by Date: Call for submissions for a forthcoming book
  • Previous by thread: Adding a Timer to a Thread
  • Next by thread: Re: Adding a Timer to a Thread
  • Index(es):
    • Date
    • Thread