This is the mail archive of the
libstdc++@sources.redhat.com
mailing list for the libstdc++ project.
Deadlock using cout, again
- To: libstdc++ at sources dot redhat dot com
- Subject: Deadlock using cout, again
- From: Maurizio Umberto Puxeddu <umbpux at tin dot it>
- Date: Thu, 17 Aug 2000 15:50:02 +0200
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