This is the mail archive of the
libstdc++@sources.redhat.com
mailing list for the libstdc++ project.
Thread deadlock problem with cout
- To: libstdc++ at sourceware dot cygnus dot com
- Subject: Thread deadlock problem with cout
- From: Craig Rodrigues <rodrigc at mediaone dot net>
- Date: Thu, 20 Jul 2000 22:11:32 -0400
Hi,
I downloaded the latest snapshots of libstdc++ from rawhide.redhat.com.
I am running:
glibc-2.1.91-2.i386.rpm
gcc-2.96-33 .i386.rpm
gcc-c++-2.96-33.i386.rpm
libstdc++-2.96-33
When I compile a C++ program, then do an ldd on that program:
ldd a.out
libpthread.so.0 => /lib/libpthread.so.0 (0x40022000)
libstdc++-libc6.2-2.so.3 => /usr/lib/libstdc++-libc6.2-2.so.3 (0x40038000)
libm.so.6 => /lib/libm.so.6 (0x4007b000)
libc.so.6 => /lib/libc.so.6 (0x4009a000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
Now, if I compile the attached program, it seems to deadlock on the
cout. If I change the cout statement to a printf, it does not
deadlock, so I am assuming some threading problems in libstdc++.
Can anyone help identify the problem?
Thanks.
--
Craig Rodrigues
http://www.gis.net/~craigr
rodrigc@mediaone.net
#include <stdio.h>
#include <pthread.h>
#include <sched.h>
#include <iostream>
void *Test(void *); // Must be void *, defined in pthread.h !
int COUNT = 0;
/**********************************************************************/
int main (int argc, char **argv)
{ pthread_t tid[4];;
int i,ret;
// Create some threads
ret = pthread_create(&(tid[0]), NULL, Test, (void *)"");
ret = pthread_create(&(tid[1]), NULL, Test, (void *)"");
printf( "Parent thread waiting...\n");
// If we don't wait for the threads, they will be killed
// before they can start...
for (i = 0; i < 2; i++)
{
ret = pthread_join(tid[i],(void **)NULL);
}
printf( "Parent thread continuing\n");
printf("COUNT = %d\n", COUNT);
}
/**********************************************************************/
void *Test(void *fname)
{
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, NULL);
int ret;
int i=0;
while ( i++ != 5)
{
ret = pthread_mutex_lock(&mutex);
COUNT++;
printf("%d\n", COUNT);
cout << "Hello in cout" << endl;
ret = pthread_mutex_unlock(&mutex);
}
}