Children of fork() Cannot pthread_create()?

David Daney ddaney at avtrex.com
Wed Jun 6 13:04:09 PDT 2007


Jerry Richards wrote:
> Hello All,
> 
> I noticed a similar forum entry that you made that is very similar to the
> problem I'm having, but I did not see any resolution to it.  I am using
> uClibc version 2.95.3 of the mips-linux-uclibc/bin/mipsel-uclibc-gcc.
> 
> I have a multi-process and multi-threaded application.  If I call
> pthread_create() in the context of a grandchild (via fork() invocations) of
> the original application process, then pthread_create() hangs (never
> returns).
> 
> If I call pthread_create() in the context of the original application
> process, then everything works fine and I am able to register lines and make
> calls.
> 
> This is the code that will hang in pthread_create() as described above:
> 
> 	pthread_t SipMonitorThread;
> 	char Arg[20];
> 	if (pthread_create(&SipMonitorThread, NULL, SipMonitorEntry, &Arg) != 0) {
> 		printf("\npthread_create of SipMonitorThread FAILED\n\n");
> 		assert(0);
> 		return;
> 	}
> 	printf("\npthread_create of SipMonitorThread SUCCEEDED\n\n");
> 
> Does anyone know why?
> 

Yes, pthread_create is not on the list of functions that can be called 
after a fork (but before exec).

The list of functions is near the end of this document:

http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html


More information about the uClibc mailing list