Bug 62098

Summary: printf() + clone(CLONE_VM | CLONE_FILES) = race condition
Product: [Retired] Red Hat Linux Reporter: Johan Walles <johan.walles>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1CC: fweimer
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-03-27 15:07:04 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
40 line C program illustrating the problem none

Description Johan Walles 2002-03-27 14:53:57 UTC
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):
glibc-2.2.4-19.3

How reproducible:
Sometimes

Steps to Reproduce:
gcc cloneprintfrace.c
./a.out


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 14:55:41 UTC
Created attachment 50864 [details]
40 line C program illustrating the problem

Comment 2 Jakub Jelinek 2002-03-27 15:10:47 UTC
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.