Children of fork() Cannot pthread_create()?

David Daney ddaney at avtrex.com
Wed Jun 6 13:19:42 PDT 2007


Daniel Jacobowitz wrote:
> On Wed, Jun 06, 2007 at 01:04:09PM -0700, David Daney wrote:
>> 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
> 
> There's no restriction on what you can do after fork; you may be
> thinking of vfork or no-MMU?
> 
From: http://www.opengroup.org/onlinepubs/009695399/functions/fork.html

.
.
.
When a programmer is writing a multi-threaded program, the first 
described use of fork(), creating new threads in the same program, is 
provided by the pthread_create() function. The fork() function is thus 
used only to run new programs, and the effects of calling functions that 
require certain resources between the call to fork() and the call to an 
exec function are undefined.

.
.
.

I am not sure if uClibc follows this, but for portable programs you 
should not call pthread_create in the child process.

David Daney


More information about the uClibc mailing list