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: Philip Mötteli <email@hidden>
- Date: Sat, 29 May 2004 11:43:06 +0200
Am 29.05.2004 um 10:26 schrieb Shaun Wexler:
On May 29, 2004, at 12:18 AM, Philip Mvtteli wrote:
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.
Here's an idea: Send a notification to the main thread using
-performSelectorOnMainThread: with the NSThread object (using
NSThread's +currentThread class method to obtain an address) as the
notification's embedded object. I don't see why that wouldn't work,
Good idea, but I create a lot of threads from different objects. How
can I be sure, that not in the same moment (or slightly before or
afterwards) another thread is forking a thread, so sending this
notification? Or, as far as I know, performInMainThread would be
executed, when the main thread enters the next time the runloop. So I
could have forked several other threads, which' notifications would
then be subsequently queued in the event queue.
Written in Mail.app:
extern NSMutableDictionary *managedThreads; // assume this exists
- (void)detachManagedThreadSelector:(SEL)selector toTarget:(id)target
withObject:(id)identifier
[]
- (void)managedThread:(id)invocation
[]
That's what I actually already did. I pass a kind of a flag/identifier
to a wrapper detach-method, using an NSInvocation as the action
description. What I do though differently, is to keep the identifier in
the thread dictionary. The moment I receive the exit notification, I
should also receive the NSThread instance id and with that, I can
evaluate the thread identifier stored in the thread dictionary.
But it's all so unnecessarily complicated, that I thought, I must have
missed something. Why doesn't NSThread' detach method just simply
return the id of its instance?
Thanks
Phil
_______________________________________________
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.