Re: NSConnection, where'd my proxy go?
Re: NSConnection, where'd my proxy go?
- Subject: Re: NSConnection, where'd my proxy go?
- From: Cryx <email@hidden>
- Date: Sat, 8 Jun 2002 00:11:18 -0500
On Friday, June 7, 2002, at 05:34 PM, Chris DeSalvo wrote:
Ugh, safely sending messages between threads shouldn't be this hard.
I'm
also still amazed that after 15+ years of development all of the
NextStep UI
frameworks aren't thread-safe.
I full heartedly agree... I was really surprised at the lack of thread
safe objects. Anyhow, here's some pruned code which I think was largely
lifted from one of Apple's samples:
- (void)startInterpreterUsingController:(id)controller {
NSPort *port1 = [NSPort port];
NSPort *port2 = [NSPort port];
objectConnection = [[NSConnection alloc]
initWithReceivePort:port1 sendPort:port2
];
[objectConnection setRootObject:controller];
[NSThread
detachNewThreadSelector:@selector(runInterpreterThread:)
toTarget:self
withObject:[NSArray arrayWithObjects:port2, port1, nil]
];
}
- (void)runInterpreterThread:(id)portArray {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSConnection *threadConnection = [NSConnection
connectionWithReceivePort:[portArray objectAtIndex:0]
sendPort:[portArray objectAtIndex:1]
];
id rootProxy = [threadConnection rootProxy];
// do your stuff
}
Daryn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.