Bug 18339 - Deadlock when using iostream with pthreads
Deadlock when using iostream with pthreads
Product: Red Hat Linux
Classification: Retired
Component: libstdc++ (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
: 20934 21108 (view as bug list)
Depends On:
  Show dependency treegraph
Reported: 2000-10-04 12:00 EDT by Brett Polivka
Modified: 2008-05-01 11:37 EDT (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2000-10-18 12:52:40 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Brett Polivka 2000-10-04 12:00:48 EDT
When using iostreams with pthreads, a deadlock occurs.  One thread may
write to a stream
just fine, but as soon as a second thread attempts to write to a stream, it
blocks on a
pthread mutex.  I have narrowed it down to the insertion of an endl into an
ostream.  As long
as an endl is not inserted, both threads can write to the stream.

Here is some sample code:

#include <iostream>
#include <unistd.h>
#include <pthread.h>

void* threadMain(void* data)
      cout << "Thread" << endl;
   return NULL;

int main()
   pthread_t thread;

   cout << "Creating thread" << endl;

   pthread_create(&thread, NULL, threadMain, NULL);

   pthread_join(thread, NULL);

This problem did not occur with older versions of libstdc++.

Brett Polivka
Comment 1 Cristian Gafton 2000-10-17 19:33:59 EDT
assigned to jakub
Comment 2 olchansk 2000-10-18 10:43:44 EDT
Please bump the priority of this bug to "High"- it breaks all C++ programs that
use threads
and iostream. This includes some of our production applications that we would
like to
be able to compile on RedHat 7 (cross compilation on RedHat 6.1 and 6.2, running
on RedHat 7.0
seems to work).
Comment 3 Jakub Jelinek 2000-10-18 12:52:38 EDT
Fixed in CVS and in the currently building gcc-2.96-60 which should appear
in rawhide soon. There will be a gcc errata after a few more bugs are killed.
See http://gcc.gnu.org/ml/gcc-patches/2000-10/msg00603.html
Thanks for the report.
Comment 4 Jakub Jelinek 2000-11-16 06:17:29 EST
*** Bug 20934 has been marked as a duplicate of this bug. ***
Comment 5 Jakub Jelinek 2000-11-21 02:01:23 EST
*** Bug 21108 has been marked as a duplicate of this bug. ***

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