boost ptime: crash in multithread application

D

daniele

I compiled the following code with mingw, but it crashes after some
seconds of execution.
Maybe the operator << with ptime is not thread safe?
I tried the same code with MS Visual C++ and it works.

#include <boost/thread.hpp>
#include <iostream>
#include <sstream>
#include <boost/date_time/posix_time/posix_time.hpp>

using namespace boost::posix_time;

void f()
{
while ( true )
{
std::eek:stringstream os;
ptime t( second_clock::local_time() );
os << t;
}
}

int main( int argc, char* argv[] )
{
boost::thread t1( f );
boost::thread t2( f );

system( "PAUSE" );

return 0;
}
 
M

Marc Zinnschlag

daniele said:
I compiled the following code with mingw, but it crashes after some
seconds of execution.
Maybe the operator << with ptime is not thread safe?
I tried the same code with MS Visual C++ and it works.

There is a gcc 3.x based version of mingw out there, that had a bug in
the stringstream implementation, which would cause random crashes when
using stringstreams with floating point numbers in a multi-threading
situation (even when each thread used its own stringstream). Can't find
the reference right now, but I experienced this bug myself.

You could try to upgrade your compiler (maybe to something gcc 4.x
based) and test it again.
 
C

Chris Ahlstrom

daniele pulled this Usenet boner:
I compiled the following code with mingw, but it crashes after some
seconds of execution.
Maybe the operator << with ptime is not thread safe?
I tried the same code with MS Visual C++ and it works.

Run your code under valgrind.
 
C

Chris Ahlstrom

daniele pulled this Usenet boner:
I compiled the following code with mingw, but it crashes after some
seconds of execution.
Maybe the operator << with ptime is not thread safe?
I tried the same code with MS Visual C++ and it works.

Run your code under valgrind.

That is, if it also crashes under Linux. I don't think there is a valgrind
for Windows, still.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top