Question

I developed a simple wrapper that encapsulates a JSONObject with Boost Property trees. The problem is a segmentation fault in this code:

void JSONObject::parse(const std::string &text)
{
    std::istringstream ss(text);
    boost::property_tree::read_json(ss, *pt);
}

A bit of context, I am using JSON for message serialization. If the program uses only one thread it works without problems. But if the program uses two threads in gives a segmentation fault in the last line of the above code.

Each thread has its own JSONObject object and none of the variables are shared between the threads. My idea is that maybe the stream is not thread safe internally.

Can anyone help me?

Was it helpful?

Solution

I found the problem. For boost property tree to be thread safe it is necessary to add this flag:

#define BOOST_SPIRIT_THREADSAFE

After adding this flag the code run without any problems.

Thanks for the help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top