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) { while(1) { cout << "Thread" << endl; usleep(100); } 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++. Thanks, Brett Polivka
assigned to jakub
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).
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.
*** Bug 20934 has been marked as a duplicate of this bug. ***
*** Bug 21108 has been marked as a duplicate of this bug. ***