famzah / popen-noshell

A much faster popen() and system() implementation for Linux
68 stars 13 forks source link

Issue when using popen-noshell in a multithreaded application? #15

Open jbglaw opened 6 years ago

jbglaw commented 6 years ago

Hi!

I don't (yet) have a lot of information about how it happens, but putting popen-noshell in a threaded application (some usual threads, as well as per-connection threads originating from libmicrohttpd), I occassionally see:

Fatal error in GNU libmicrohttpd daemon.c:2039: Failed to join a thread

followed by the libmicrohttpd exiting the application... Not yet sure if this is a libmicrohttpd bug, or an interference with pthreads itself. The above error message is printed with pthread_join() fails. (ESRCH is returned, and if I decoded the pthread_t correctly, it's ->tid field is zero.)

So this is just a heads-up, or maybe you have a hint right away. I'll add anything I find out of course.

Thanks, Jan-Benedict

famzah commented 6 years ago

Hello,

I don't have much experience with multi-threaded applications. Please take a look at issue #11 where lots of stuff regarding this matter is discussed. I tried to summarize the caveats in the main README file (see at the bottom).

nicowilliams commented 6 years ago

Maybe the clone() call interferes with the C/pthread library's tracking of threads? What happens if you build with POPEN_NOSHELL_VALGRIND_DEBUG defined? You could also modify this library to use vfork() instead as discussed in earlier issues. Other than clone(), I don't see what could do it -- this library is clearly thread-safe in that there is no global (nor static global) state. (Well, there is the environ, but let's ignore that for now.)