• 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: How to set up a thread listening to performSelector: messages?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to set up a thread listening to performSelector: messages?


  • Subject: Re: How to set up a thread listening to performSelector: messages?
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Thu, 25 Sep 2008 18:17:40 +0200


Le 25 sept. 08 à 17:53, Oleg Krupnov a écrit :

I actually have tried this. My code looks like this (is it correct?):

@implementation Worker

- (void)threadMain:(id)data
{
 runLoop = [NSRunLoop currentRunLoop];
 [runLoop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode];
 while(true)
 {
       [runLoop run];
 }
}

- (void)processRequest:(id)sender
{
 NSLog(@"hello");
}

@end

Then from the main thread I send:

[[worker runLoop] performSelector:@selector(processRequest:)
target:worker argument:request order:0 modes:[NSArray
arrayWithObject:NSDefaultRunLoopMode]];


NSRunLoop is not known to be thread safe. Calling another thread's runloop methods does not works (as you see). You should only use this method one the current thread runloop.

Instead you should keep a pointer to the target thread and use [worker performSelector:onThread:withObject:waitUntilDone:].
Note that It works only on 10.5.


_______________________________________________

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


References: 
 >How to set up a thread listening to performSelector: messages? (From: "Oleg Krupnov" <email@hidden>)
 >Re: How to set up a thread listening to performSelector: messages? (From: Ken Thomases <email@hidden>)
 >Re: How to set up a thread listening to performSelector: messages? (From: "Oleg Krupnov" <email@hidden>)

  • Prev by Date: Re: How to set up a thread listening to performSelector: messages?
  • Next by Date: Re: How to set up a thread listening to performSelector: messages?
  • Previous by thread: Re: How to set up a thread listening to performSelector: messages?
  • Next by thread: Filtering an NSArrayController using a to-many relationship
  • Index(es):
    • Date
    • Thread