Re: How to set up a thread listening to performSelector: messages?
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