I found that when endl is output to ostream, the locks sometimes are not freed. If two or more threads do output to stderr, it finally results in deadlock. Somehow, one has to output more than one endl. It does not work with "\n", only with endl. The minimal version of this bug is manifest even in single-threaded application compiled with -lpthread, though. Here is an example: ////////// Code starts here ///////// #include <iostream.h> #include <stdio.h> // // Compile: // // g++ -g -o t t.cc -lpthread // int lock_count () { return ((pthread_mutex_t *)stderr->_lock)->__m_count ; } main () { cerr << "BEFORE endls: lock count = " << lock_count (); cerr << endl << endl; // Does not work with only 1 endl cerr << "AFTER: lock count = " << lock_count () << endl; } //////////////// Code ends here //////////////// On my system, it produces the following output: ------------------------------------------------- avs % ./t BEFORE endls: lock count = 0 AFTER: lock count = 1 ------------------------------------------------ So the lock is not released, as you can see. Information that may be relevant: RedHat 7.0 avs % rpm -q glibc libstdc++ gcc glibc-2.1.94-3 libstdc++-2.96-54 gcc-2.96-54
*** This bug has been marked as a duplicate of 18339 ***