Using the stream checking functions (or conversions that call those functions) fail when -pthread is applied. They always report the stream as being good. Calling the fail() function on the stream always returns false, and good() always returns true. These functions work as expected when -pthread is not used. I have executed all of these tests in the debugger, and the stream testing functions are never entered to perform these tests--it acts like a boolean value was used in place of the function call--when -pthread was applied. The same erroneous functionality can be obtained by adding a #define _THREAD_SAFE to the top of the source. Proper execution can be obtained by using a static cast to convert the ifstream to an istream (strange, but this works): while(static_cast<std::istream&>(file)) { ... } All other stream operations function correctly when the stream is used through the istream reference. I have verified proper operation of this test case under Linux, using various versions of g++. Attempts to duplicate the problem using a stringstream (to simplify the test case) fail, as the stringstream acts properly. Other stream types and user-defined streams derived from std::istream fail. ------------------- // file: stream_test.cpp // // To break this (gcc-3.3.3): // g++ stream_test.cpp -o stream_test -pthread // // To allow it to work, just remove the -pthread: // g++ stream_test.cpp -o stream_test #include <fstream> #include <iostream> int main(int argc, char** argv) { (void) argc; (void) argv; std::ifstream file("stream_test.cpp"); while(file) { char c; file.get(c); std::cout << c << std::flush; } return 0; } ------------------- $ g++ -v Reading specs from /usr/local/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.3/specs Configured with: /mnt/nfs_kevin/foo/gcc-3.3.3/configure --prefix=/usr/local --enable-shared --enable-threads --disable-multilib --enable-languages=c,c++ --enable-symvers=no : (reconfigured) /mnt/nfs_kevin/foo/gcc-3.3.3/configure --prefix=/usr/local --enable-shared --enable-threads --disable-multilib --enable-languages=c,c++ --enable-symvers=no --disable-nls Thread model: aix gcc version 3.3.3 Note: This has had the 'collect2.c' patch from Bug 13878 applied, and the C++ standard library /usr/local/lib/libstdc++.a has had all of the static members removed (which were included due to another bug, number now forgotten) so that only the dynamic library is present: $ dump -a /usr/local/lib/libstdc++.a ***Archive Header*** Member Name Date Uid Gid Mode Size libstdc++.so.5 Apr 07 20:53:54 2004 0 0 000755 0x005ad304
Created attachment 6068 [details] Preprocessed source when -pthread is used
Created attachment 6069 [details] Preprocessed source when -pthread is not used.
I have also found this erroneous behavior with cvs version 3.3.4 (20040412), which was compiled with no modifications. The sample code, when compiled with gcc-3.3.2 (ltconfig/collect2.c patched), works correctly.
Does this work in a 3.4 prerelease?
The 3.4 prerelease won't compile. The assembler is at fault, as it gets stuck in an infinite loop while building the C++ standard library. I even attached a debugger to it and watched it spin on about 6 instructions. The gcc platform-specific information page says there's an APAR for it which is TBD, but I couldn't find a patch for it on the IBM web site.
The AIX as and ar patches for AIX 5.1 and AIX 5.2 now are available from the IBM Techsupport website.
I was finally able to get the latest IBM patches installed, and gcc 3.4 (3.4.1 20040511) does work properly for this test.
Closing as fixed for 3.4.1.