This is the mail archive of the libstdc++@sources.redhat.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Deadlock using cout, again


Hello.

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" <<
endl;).
With the print operator commented out in the main() the thread will work
fine.
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;
}

int
main(void)
{
  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.

Compiler:
GCC cvs version checked out on Thu Aug 17 15:26 CEST 2000
Standard library:
libstdc++-3-libc6.1-2-2.10.0.0

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
me.

Any suggestion welcome. Thanks for your time,

Maurizio Umberto Puxeddu

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]