The posix_spawn implementation in libc uses vfork. How is the POSIX requirement that posix_spawn must be safe in multi threaded application met if it relies on vfork which is *not* reliable in multi threaded applications?
Olga On Wed, Jul 14, 2010 at 8:28 PM, <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, and any application specific locking. 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. > > A solution that creates a new process without a call to fork is the best > idea I've heard so far. Unfortunately, as Bart has already observed, > it's a lot of work for a gain that has yet to be quantified. > > -j > _______________________________________________ > on-discuss mailing list > on-disc...@opensolaris.org > http://mail.opensolaris.org/mailman/listinfo/on-discuss > -- , _ _ , { \/`o;====- Olga Kryzhanovska -====;o`\/ } .----'-/`-/ olga.kryzhanov...@gmail.com \-`\-'----. `'-..-| / http://twitter.com/fleyta \ |-..-'` /\/\ Solaris/BSD//C/C++ programmer /\/\ `--` `--` _______________________________________________ perf-discuss mailing list perf-discuss@opensolaris.org