Bug 62098 - printf() + clone(CLONE_VM | CLONE_FILES) = race condition
printf() + clone(CLONE_VM | CLONE_FILES) = race condition
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2002-03-27 09:53 EST by Johan Walles
Modified: 2007-04-18 12:41 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2002-03-27 10:07:04 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
40 line C program illustrating the problem (835 bytes, text/plain)
2002-03-27 09:55 EST, Johan Walles
no flags Details

  None (edit)
Description Johan Walles 2002-03-27 09:53:57 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020214

Description of problem:
Run the attached program a couple of times.  Roughly half of the times
one of the lines is printed twice, or some characters aren't printed
at all.  I have tried it on three separate machines, a single CPU
x86 Debian Testing one, a 2 CPU x86 with RH7.1, and another single CPU
x86 with RH6.2.  All three machines have similar problems.

I also have problems with crashes when using clone() and printf()
together that may be related to this, but I'll report that separately
when I can provoke it with a short example program.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
gcc cloneprintfrace.c

Actual Results:  Varying, but here's one bogus one.  Note that the first line is
printed twice.

Parent 30785: This is a random printout
Parent 30785: This is a random printout
Child 30786: Hello
Child 30786: Good bye

Expected Results:

Parent 31394: This is a random printout
Child 31395: Hello
Child 31395: Good bye

Additional info:

This bug has been reported in Debian's bug reporting system as well, at
"http://bugs.debian.org/140155".  Based on blind guessing however, I recon you
may be faster at fixing these kinds of problems.
Comment 1 Johan Walles 2002-03-27 09:55:41 EST
Created attachment 50864 [details]
40 line C program illustrating the problem
Comment 2 Jakub Jelinek 2002-03-27 10:10:47 EST
This is not a glibc bug.
If you are using clone directly (as opposed to using pthread_create), you're
responsible for locking too. printf (well, not only that) is thread safe
because it uses pthread_mutex* etc. If you don't want to use -lpthread, you
either need to write a threading library of your own which will at least
provide the locking semantics glibc need, or use some locking around all
calls you make into foreign libraries which need thread safety.

Note You need to log in before you can comment on or make changes to this bug.