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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to