Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concurrency problems wih Boost Property tree

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?

like image 987
mariolpantunes Avatar asked Jan 03 '13 13:01

mariolpantunes


1 Answers

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.

like image 191
mariolpantunes Avatar answered Nov 17 '22 00:11

mariolpantunes