[Bug libstdc++/15015] New: Thread safety / race condition bug in iostreams on Solaris 5.9
harri dot pasanen at trema dot com
gcc-bugzilla@gcc.gnu.org
Mon Apr 19 16:03:00 GMT 2004
The following test program segfaults maybe 50% of the time on a SMP Solaris box,
when compiled with gcc 3.2.3. On Linux (Mandrake 9.1, default gcc 3.2.3) it seems to
work fine. gcc 3.3.2 on HP-UX 11.00 also seemed to work.
I went through the libstdc++-v3 ChangeLog, but I did not find any particular reference
to this problem, or a fix.
/*****************************************************
Test code to exercise iostreams under threads
Compile with:
g++ -Wall -O2 thread-iostream.cxx -lpthread
Execute:
./a.out
******************************************************/
#include <pthread.h>
#include <iostream>
#include <sstream>
const int num_threads = 200;
void *runner(void * param); /* function that the thread will execute */
int main (int argc, const char **argv)
{
pthread_t tid[num_threads];
for (int i = 0; i < num_threads; i ++)
pthread_create( &tid[i], NULL, runner, NULL);
for (int i = 0; i < num_threads; i ++)
pthread_join( tid[i], NULL); // makes the main code wait for the thread
std::cout << "Exiting ok.\n";
return 0;
}
void * runner(void *param)
{
std::stringstream fmt;
for (int i = 0; i < 10; i++)
fmt << "today" << 3.14157 << "is bogus\n";
pthread_exit(0);
return 0;
}
// EOF for thread-iostream.cxx
$ g++ -v
Reading specs from /usr/gnu/lib/gcc-lib/sparc-sun-solaris2.9/3.2.3/specs
Configured with: ../gcc-3.2.3/configure --prefix=/usr/gnu --with-gnu-as
--with-cpu=supersparc --with-gnu-ld --enable-version-specific-runtime-libs
--enable-long-long --enable-threads --enable-languages=c,c++
Thread model: posix
gcc version 3.2.3
The backtrace is:
#0 std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> >
>::_M_widen_float(std::ostreambuf_iterator<char, std::char_traits<char> >,
std::ios_base&, char, char*, int) const (this=0xff2f9838, __s=
{<iterator<std::output_iterator_tag,void,void,void,void>> = {<No data fields>},
_M_sbuf = 0xfe7fbea4, _M_failed = false}, __io=@0xfe7fbf0c, __fill=32 ' ',
__cs=0xfe7fbc20 "@\t!ïsÃÃý", __len=7)
at
/raid5/BuildSwBuild/gcc-3.2.3-build/sparc-sun-solaris2.9/libstdc++-v3/include/bits/locale_facets.h:488
4
-Harri
harri.pasanen at trema.com
--
Summary: Thread safety / race condition bug in iostreams on
Solaris 5.9
Product: gcc
Version: 3.2.3
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: harri dot pasanen at trema dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15015
More information about the Gcc-bugs
mailing list