Deadlock using cout, again

Maurizio Umberto Puxeddu
Thu Aug 17 06:52:00 GMT 2000


I'm experiencing a deadlock printing on cout from multiple threads.
In the following code the secondary thread deadlocks if and only if the
main thread has previously printed on cout (uncomment cout << "Hello" <<
With the print operator commented out in the main() the thread will work
I compiled this code with and without -D_REENTRANT (it doesn't matters).

#include <pthread.h>

#include <iostream>
using namespace std;

void *
entryPoint(void *)

  for (int i = 0; i < 100000; ++i)
    cout << i << endl;

  return 0;

  pthread_t thread;

  //cout << "Hello" << endl;

  pthread_create(&thread, 0, entryPoint, 0);

  pthread_join(thread, 0);

  return 0;

I'm running Redhad Linux 6.2 with kernel 2.2.14-5.0.

GCC cvs version checked out on Thu Aug 17 15:26 CEST 2000
Standard library:

I found a similar thread on this ML. The only solution to this problem
was compiling GCC with --enable-threads=posix but it is not enough for

Any suggestion welcome. Thanks for your time,

Maurizio Umberto Puxeddu

More information about the Libstdc++ mailing list