Help save net neutrality! Learn more.
Close

#1969 get float/double from std::stringstream in multi-thread crash!

OTHER
assigned
Support
none
Unknown
False
2014-08-19
2013-05-09
Meng Jie
No

When I run the following function in multi-thread (2 or more) at same time (single-thread is ok), the application got an exception, and callstack cannot locate where it happens.
mingw version tried: 4.4.0, 4.7.1, and the newest.

void func()
{  
    std::string str = "3.56";  
    double out = 0;
    std::stringstream ss;
    ss << str;
    ss >> out;
}

if the variable 'out' is int, it is ok, it only happens on float, double, long double.
these codes are ok on msvc.

Discussion

  • Earnie Boyd

    Earnie Boyd - 2013-05-09

    Please provide a SSCCE which shows the problem. Your function alone isn't enough.

    Your problem could be from one of two places, the first part of this problem is to determine which place the problem stems.

     
    • Meng Jie

      Meng Jie - 2013-05-10

      SSCCE posted.

       
  • Earnie Boyd

    Earnie Boyd - 2013-05-09
    • labels: --> WSL?, libstdc++
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,6 +1,7 @@
     When I run the following function in multi-thread (2 or more) at same time (single-thread is ok), the application got an exception, and callstack cannot locate where it happens.
     mingw version tried: 4.4.0, 4.7.1, and the newest.
    
    +~~~~~~
     void func()
     {  
         std::string str = "3.56";  
    @@ -9,6 +10,7 @@
         ss << str;
         ss >> out;
     }
    +~~~~~~
    
     if the variable 'out' is int, it is ok, it only happens on float, double, long double.
     these codes are ok on msvc.
    
    • status: unread --> assigned
    • assigned_to: Earnie Boyd
     
  • Meng Jie

    Meng Jie - 2013-05-09
    //************* SSCCE ******************//
    
    #include <iostream>
    #include <string>
    #include <sstream>
    #include <process.h>
    
    using namespace std;
    
    unsigned int threadFunc(void* param)
    {
        //do loops to make it happen more easily.
        for (int i=0; i<100; ++i)
        {
            std::stringstream ss;
            std::string str("3.14");
            //float, double, long double will crash, int will be ok.
            double out(0);
    
            ss<<str;
            ss>>out;
    
            std::cout<<out<<std::endl;
        }
    
        return 0;
    }
    
    void createThread()
    {
        ::_beginthreadex(0,
                        0,
                        (unsigned int (__stdcall*)(void*))threadFunc,
                        0,
                        0,
                        0);
    }
    
    int main(int argc, char* argv[])
    {
        //if i<1, only one thread, it will be ok.
        for (int i=0; i<10; ++i)
            createThread();
    
        //wait for some input, then quit.
        std::string str;
        std::cin>>str;
    
        return 0;
    }
    
     
    Last edit: Earnie Boyd 2013-05-10
  • Earnie Boyd

    Earnie Boyd - 2013-05-10

    WJFFM. Give me your command line.

    g++ -O0 -o mingw-bug-1969.exe /downloads/main.cpp
    
     
  • Meng Jie

    Meng Jie - 2013-05-10

    Sorry, I don't know what you mean by "Give me your command line".
    you mean how I built it?
    g++ -c main.cpp
    g++ -o main.exe main.o
    just type the them in windows cmd.

     
    Last edit: Meng Jie 2013-05-10
  • Earnie Boyd

    Earnie Boyd - 2013-05-10

    Sorry, I don't know what you mean by "Give me your command line".
    you mean how I built it?

    Yes that is exactly what I meant.

    When I build your attached main.cpp as you've stated you build it, I'm able to execute the result without issue. The GCC version I'm using is 4.7.2 and the binutils versions is 2.23.1.

    Your attached .exe didn't even begin to start and I had to ^C it.

    Can you try with GCC 4.7.2 and binutils 2.23.1?

     
  • Meng Jie

    Meng Jie - 2013-05-10

    GCC 4.7.2 already tried yesterday(fail), I use mingw-get-inst install and select download latest repository catalogs.
    But binutils never used.
    I'll try binutils 2.23.1 tomorrow. Thank you.

     
  • Earnie Boyd

    Earnie Boyd - 2013-05-10

    The mingw-get-inst is a one time use program. You should use mingw-get on the command line to upgrade your packages.

    mingw-get update
    mingw-get upgrade mingw32-g++ mingw32-binutils

     
  • Meng Jie

    Meng Jie - 2013-05-11

    I'm sorry to say it did not work, either.

    In gcc version 4.7.2 (GCC),

    first I input "mingw-get update",
    then "mingw-get upgrade mingw32-g++ mingw32-binutils",
    I got:

    mingw-get: ERROR mingw32-g++: unknown package
    mingw-get: WARNING upgrade mingw32-binutils-doc: request ignored...
    mingw-get: WARNING mingw32-binutils-doc: package was not previously inst
    alled
    mingw-get: WARNING mingw32-binutils-doc: it will remain this way until y
    ou...
    mingw-get: WARNING use 'mingw-get install mingw32-binutils-doc' to insta
    ll it
    mingw-get: WARNING upgrade mingw32-binutils-lang: request ignored...
    mingw-get: WARNING mingw32-binutils-lang: package was not previously ins
    talled
    mingw-get: WARNING mingw32-binutils-lang: it will remain this way until
    you...
    mingw-get: WARNING use 'mingw-get install mingw32-binutils-lang' to inst
    all it
    upgrade: binutils-2.23.1-1-mingw32-bin.tar.lzma
    mingw-get: INFO package binutils-2.23.1-1-mingw32-bin.tar.lzma is up to
    date

    Then I compile my code, still got the exception.

     

Log in to post a comment.