Is posix_spawnp thread-safe?

Especially: is posix_spawnp configured for using vfork + execve threadsafe on Linux?

Man page doesn't document this nor I couldn't find any trustworthy information on the Internet. I found system() or vfork() are not guaranteed to be thread-safe on Solaris, so I'm suspecting posix_spawnp might be unsafe too.

Well, at least after spending over two days debugging some code, I'm almost sure our code doesn't have any race conditions, but for some strange reasons it sometimes *does* hang in 1 per 1000 invocations, when there are many parallel child processes spawned. So, how is it? Is it a bug in posix_spawnp, or is it just so by design?
That's an interesting function.

This link: http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html has an interesting paragraph that begins with:
We can identify several problems with posix_spawn() and posix_spawnp(), but there does not appear to be a solution that introduces fewer problems. ... It is also complicated to modify the environment of a multi-threaded process temporarily, since all threads must agree when it is safe for the environment to be changed.

I'm not sure what that means, but it may be relevant for you.
Hmm, it seems that posix_spawnp is kinda thread-safe. Kinda, because it is impossible to use it correctly in multithreaded environment, except for some tiny programs. The child process inherits all the parent file descriptors and there is no reliable way of closing them as it is when using fork + exec directly. This makes some of our file descriptors remain open and block read operations.
Last edited on
Topic archived. No new replies allowed.