Bug 18339 - Deadlock when using iostream with pthreads
Summary: Deadlock when using iostream with pthreads
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: libstdc++
Version: 7.0
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
: 20934 21108 (view as bug list)
Depends On:
TreeView+ depends on / blocked
Reported: 2000-10-04 16:00 UTC by Brett Polivka
Modified: 2008-05-01 15:37 UTC (History)
4 users (show)

Clone Of:
Last Closed: 2000-10-18 16:52:40 UTC

Attachments (Terms of Use)

External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2000:132 normal SHIPPED_LIVE Bug fixing update of GCC 2.96 2000-12-19 05:00:00 UTC

Description Brett Polivka 2000-10-04 16:00:48 UTC
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 23:33:59 UTC
assigned to jakub

Comment 2 olchansk 2000-10-18 14:43:44 UTC
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 16:52:38 UTC
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 11:17:29 UTC
*** Bug 20934 has been marked as a duplicate of this bug. ***

Comment 5 Jakub Jelinek 2000-11-21 07:01:23 UTC
*** 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.