This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/10193: Regression: iostreams no longer threadsafe
- From: peturr02 at ru dot is
- To: gcc-gnats at gcc dot gnu dot org
- Date: 23 Mar 2003 19:24:36 -0000
- Subject: libstdc++/10193: Regression: iostreams no longer threadsafe
- Reply-to: peturr02 at ru dot is
>Number: 10193
>Category: libstdc++
>Synopsis: Regression: iostreams no longer threadsafe
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Mar 23 19:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: peturr02 at ru dot is
>Release: gcc-3.2.2
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
The iostreams implementation in gcc-2.95.x was reasonably threadsafe, as is stdio on glibc-2.3. The implementation of iostreams in gcc-3.x is however not threadsafe at all.
>How-To-Repeat:
See attachment.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="threadbug.cc"
Content-Disposition: inline; filename="threadbug.cc"
#include <iostream>
#include <sstream>
#include <vector>
#include <cstdlib>
#include <unistd.h>
#include <pthread.h>
void* thread(void* p)
{
using namespace std;
int n = *static_cast<int*>(p);
for (;;)
{
ostringstream stream;
stream << "thread" << n << '\n';
clog << stream.str();
}
return 0;
}
struct threadstuff
{
pthread_t t;
int n;
};
int main(int argc, char** argv)
{
using namespace std;
int numthreads = 10;
if (argc > 1)
numthreads = atoi(argv[1]);
vector<threadstuff> vec (numthreads);
pthread_attr_t attr;
pthread_attr_init(&attr);
for (int i = 0; i < numthreads; ++i)
{
vec[i].n = i;
pthread_create(&vec[i].t, &attr, &thread, &vec[i].n);
}
sleep(10);
return 0;
}