Re: NSTask - Notification and Threads
Re: NSTask - Notification and Threads
- Subject: Re: NSTask - Notification and Threads
- From: Ken Thomases <email@hidden>
- Date: Thu, 5 Mar 2009 16:45:05 -0600
On Mar 5, 2009, at 4:22 PM, Seth Willits wrote:
It seems to me that the thread a task was launched on must continue
to exist until the thread is terminated, in order for the task to
send NSTaskDidTerminateNotification. I can either make my thread
continue to exist (I'd prefer not) or I can make the launch happen
on the main thread [...]
I find it odd the docs don't mention this, but maybe it's one of
those things I'm "just supposed to know."
Yeah. You can provide feedback for the documentation to ask for
clarification.
In order for the framework to know when the task has exited it has to
monitor an external resource or event. The description of the
NSTaskDidTerminateNotification notification hints at this. Monitoring
of such external resources/events is typically done through the run
loop. It's not really feasible to install the run loop source onto
the run loop of some other thread, so it naturally uses the current
thread. That also seems least surprising -- least surprising once you
know that a run loop is involved, that is -- to the developer as
client of the framework.
So, it's not even sufficient that the launch thread continues to
exist, it must run its run loop.
By the way, you don't necessarily need to use a condition lock to
learn when the task has been launched. If you have the secondary
thread tell the main thread to launch the task using -
performSelectorOnMainThread:withObject:waitUntilDone: and pass YES for
the wait parameter, you get that synchronization pretty simply.
Cheers,
Ken
_______________________________________________
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