Re: How to know, which NSThread has terminated?
Re: How to know, which NSThread has terminated?
- Subject: Re: How to know, which NSThread has terminated?
- From: Shaun Wexler <email@hidden>
- Date: Sat, 29 May 2004 01:38:10 -0700
On May 28, 2004, at 4:57 PM, Philip Mvtteli wrote:
>
When I fork a thread using
>
>
+(void)detachNewThreadSelector:(SEL)aSelector toTarget:aTarget
>
withObject:anArgument
>
>
I have no idea how to recognize this just created thread later, when
>
it terminates. What I need is something like a handle. I mean
>
objc_thread_detach() gives back an objc_thread_t too.
>
I could put some flag into the tread dictionary, but it would be so
>
much nicer to be able to just ask the thread for its handle or to keep
>
the address of the NSThread instance. But because there's void as the
>
return value, all this is not possible.
>
How do people keep track of a specific thread, using NSThread?
Written in Mail.app:
- (void)detachManagedThreadSelector:(SEL)selector toTarget:(id)target
withObject:(id)identifier
{
NSMethodSignature *signature = [target
methodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation
invocationWithMethodSignature:signature];
[invocation setTarget:target];
[invocation setSelector:selector];
[invocation setArgument:[identifier retain] atIndex:2];
[NSThread detachNewThreadSelector:@selector(managedThread:)
toTarget:self withObject:invocation];
}
- (void)managedThread:(id)invocation
{
NSAutoreleasePool *pool = [[NSAutoreleasePool allocWithZone:NULL]
init];
id identifier;
[invocation getArgument:&identifier atIndex:2];
if (identifier) {
@synchronized(managedThreads) {
[managedThreads setObject:[NSThread currentThread]
forKey:identifier];
}
}
@try {
// set up any connections, ports, pipes, etc.
[invocation invoke];
}
@catch (NSException *exception) {
[NSApp reportException:exception];
}
@finally {
// clean up connections, etc.
}
if (identifier) {
@synchronized(managedThreads) {
[managedThreads removeObjectForKey:identifier];
[identifier release];
}
}
[pool release];
}
--
Shaun Wexler
MacFOH
http://www.macfoh.com
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.