boost ptime: crash in multithread application

Discussion in 'C++' started by daniele, Mar 10, 2010.

  1. daniele

    daniele Guest

    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;
    }
     
    daniele, Mar 10, 2010
    #1
    1. Advertising

  2. daniele wrote:
    > 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.
     
    Marc Zinnschlag, Mar 10, 2010
    #2
    1. Advertising

  3. 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.

    --
    You are deeply attached to your friends and acquaintances.
     
    Chris Ahlstrom, Mar 11, 2010
    #3
  4. 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.

    --
    You are deeply attached to your friends and acquaintances.
     
    Chris Ahlstrom, Mar 11, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steve
    Replies:
    1
    Views:
    3,873
    Larry Barowski
    Jun 15, 2004
  2. r_obert@REMOVE_THIS.hotmail.com

    Multithread or Multithread DLL?

    r_obert@REMOVE_THIS.hotmail.com, Nov 27, 2004, in forum: C++
    Replies:
    0
    Views:
    2,255
    r_obert@REMOVE_THIS.hotmail.com
    Nov 27, 2004
  3. Replies:
    3
    Views:
    478
    peter koch
    Aug 15, 2008
  4. Mr. Murdock

    Webservice drops multithread application

    Mr. Murdock, Feb 26, 2008, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    129
    Mr. Murdock
    Mar 3, 2008
  5. Regis d'Aubarede
    Replies:
    8
    Views:
    183
    zuerrong
    Dec 17, 2010
Loading...

Share This Page