On Wed, Jul 14, 2010 at 11:28:17AM -0700, johan...@opensolaris.org wrote:
> On Wed, Jul 14, 2010 at 12:32:26AM -0500, Nicolas Williams wrote:
> > One possible improvement that comes to mind would be a private vforkx()
> > flag to request that threads in the parent other than the one calling
> > vforkx() not be stopped.  The child would have to be extremely careful
> > to not call malloc() or do anything that might disturb the state of the
> > parent beyond the current stack frame, which is why such a flag would
> > have to be private and undocumented.  But this should not be considered
> > until someone first shows that posix_spawn() performance is a problem
> > and that the parent thread stop/resume overhead is the biggest ticket
> > item.
> 
> It's significantly more complicated than that.  You'd have to ensure
> that there are no race conditions between the atfork handlers, rtld,
> libc, ...

there are no atfork handlers in the vfork case, and you could make the
rtld block without having to stop all threads in the parent.  A careful
examination of this approach will surely show a few more such gotchas,
probably none fatal, but all problematic enough that such a vforkx()
extension would have to be private and undocumented.

>  ..., and any application specific locking.  [...]

Wouldn't apply here since only posix_spawn(3C) would actually use this.

>                                              The vfork manual is already
> pretty clear that all bets are off should you use this in a
> multi-threaded application:
> 
>      The  use  of  vfork()  or vforkx() in multithreaded applica-
>      tions, however, is unsafe due to race  conditions  that  can
>      cause  the  child  process  to  become deadlocked and conse-
>      quently block both the child and parent process from  execu-
>      tion indefinitely.

This doesn't apply to posix_spawn(3C) however.  That is, it is possible
to use vforkx() in a thread-safe way, and posix_spawn(3C) does just
that:

     ____________________________________________________________
    |       ATTRIBUTE TYPE        |       ATTRIBUTE VALUE       |
    |_____________________________|_____________________________|
    | Interface Stability         | Committed                   |
    |_____________________________|_____________________________|
    | MT-Level                    | MT-Safe                     |
    |_____________________________|_____________________________|


It's also possible to hang yourself with vforkx().  Fortunately
posix_spawn(3C) doesn't do that.

Nico
-- 
_______________________________________________
on-discuss mailing list
on-discuss@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/on-discuss

Reply via email to