std::string, std::ostringstream behaves unpredictably in multithreaded environment.

L.Suresh suresh@comodogroup.com
Thu Aug 26 14:22:00 GMT 2004


Hi,

I'm using pthreads on Fedora Core 1.

I have compiled my entire project with

-D_REENTRANT 
-D_MULTI_THREADED

I get Segmentation faults for naive code that uses std::string's
operator+, std::ostringstream's operator<< as a local variable in stack.

std::string Formatter::format(const LogRecord& record) const
{
    std::ostringstream ost;
    ost << record.getTime() << "  " << record.getMessage(); //<--Crashes
    return ost.str();
}

Do i have to do anything extra in order for my program to behave
predictably in multi-threaded environment?

Regards,
L.Suresh.





More information about the Gcc-help mailing list