Bug 62098 - printf() + clone(CLONE_VM | CLONE_FILES) = race condition
Summary: printf() + clone(CLONE_VM | CLONE_FILES) = race condition
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc
Version: 7.1
Hardware: i686
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-03-27 14:53 UTC by Johan Walles
Modified: 2016-11-24 15:15 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2002-03-27 15:07:04 UTC
Embargoed:


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

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.


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