Is std::ostringstream thread safe for Embarcadero C++ Builder XE4?

613 Views Asked by At

I have an application that is throwing exceptions when my program terminates. I have the following utility function in a header file for converting numeric types to std::strings that I use to avoid my code being littered with std::ostringstream instances

namespace MyUtils {

    template <typename T>
    std::string NumericToString(const T& value)
    {
        std::string str_retval = "";
        try
        {
            std::ostringstream ost;
            ost << value;
            str_retval = ost.str();
        }
        catch (std::exception& e)
        {
            str_retval = "?";
        }
        return str_retval;
    }   
}

Now this code is called from multiple threads and is called often and it is occaisonally throwing an access violation exception deep inside the ostringstream implementation. From what I can see of this code I can see no obvious reason why it is not thread safe.

I use an identical function inside other applications that I develop specifically for Linux (g++ 4.6.3) and I have never seen the code throw.

I know that thread safety inside the standard library should never be assumed, but my function is pretty basic. My application is built as a 64-bit application so it is making use of the C++11 compiler that ships with this version of XE4.

Can anyone tell me if there is any reason why my above function is unsafe, or indeed if there are any known issues with the Embarcadero C++ builder XE4 implementation of the standard library that makes this an unsafe thing to do?

0

There are 0 best solutions below