Re: pthread - system() blocking
Re: pthread - system() blocking
- Subject: Re: pthread - system() blocking
- From: Greg Parker <email@hidden>
- Date: Tue, 1 Mar 2011 01:47:41 -0800
On Mar 1, 2011, at 1:36 AM, Chris Suter wrote: On Tue, Mar 1, 2011 at 7:52 PM, Tilghman Lesher < email@hidden> wrote: I'd stick with the fork/exec, so you can deal with these issues directly.
But can't you do with posix_spawn_file_actions whatever you'd want to do with fork/exec?
No.
The problem is that there's no "close all but these" file action for posix_spawn(). There's no safe way for posix_spawn() to create a child process with all descriptors closed except a known set like stdin/out/err. You cannot safely use posix_spawn_file_actions_addclose() for every open descriptor in the parent, because other threads in the parent may be concurrently opening and closing those descriptors between the time you set up the file actions and the time you call posix_spawn().
With fork/exec, you can fork, then close descriptors in the child, then exec. This is thread-safe with respect to concurrent open and close because between fork and exec there's only one thread in the child.
--
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden