Boost C++ Libraries: Ticket #11662: Parse Json https://svn.boost.org/trac10/ticket/11662 <p> use Boost to Parse Json on linux! when I use it with multithreading ,the Program crash!! </p> <p> my code: json_test.h </p> <pre class="wiki">#ifndef UNIT_JSON_BUGTEST_H #define UNIT_JSON_BUGTEST_H #include &lt;boost/property_tree/ptree.hpp&gt; #include &lt;boost/property_tree/json_parser.hpp&gt; #include &lt;boost/foreach.hpp&gt; #include &lt;boost/thread/thread.hpp&gt; #include &lt;sstream&gt; #include &lt;map&gt; using namespace boost; using namespace boost::property_tree; using namespace std; #define JSON_BUG "{\"onlineUser\":[{\"username\":\"131898@QQ.COM\",\"framedipaddress\":\"10.10.1.3\"},{\"username\":\"a258055085@163.com\",\"framedipaddress\":\"10.10.1.4\"},{\"username\":\"77476848@QQ.COM\",\"framedipaddress\":\"10.10.1.5\"},{\"username\":\"tyws0001@163.com\",\"framedipaddress\":\"10.10.1.10\"},{\"username\":\"zbr7066895@163.com\",\"framedipaddress\":\"10.10.1.9\"},{\"username\":\"1733064835@qq.com\",\"framedipaddress\":\"10.10.1.12\"}]}" typedef multimap&lt;string, string&gt; onlineuser_map; onlineuser_map get_online_user_map(const string strJson); void unit_json_bugtest_main(); #endif </pre><p> json_test.cpp </p> <pre class="wiki">#include "unit_json_bugtest.h" onlineuser_map get_online_user_map(const string strJson) { onlineuser_map mymap; // cout &lt;&lt; strJson &lt;&lt; endl; stringstream ssJson(strJson); ptree pt; try{ read_json(ssJson, pt); } catch(...) { cout &lt;&lt; "read json string error" &lt;&lt;endl; return mymap; } try{ ptree ptInfoArray = pt.get_child("onlineUser"); BOOST_FOREACH(ptree::value_type &amp;v, ptInfoArray) { ptree ptChild; std::stringstream streamChild; write_json(streamChild, v.second); json_parser::read_json(streamChild, ptChild); mymap.insert(make_pair(ptChild.get&lt;string&gt;("username"), ptChild.get&lt;string&gt;("framedipaddress"))); } } catch(...) { mymap.clear(); cout &lt;&lt; "read json string error" &lt;&lt;endl; return mymap; } return mymap; } int i; void my_thread_fun(int itest) { get_online_user_map(JSON_BUG); cout &lt;&lt; "i'm OK!!: " &lt;&lt; itest&lt;&lt;endl; } void main() { i = 0; while(1) { thread th(my_thread_fun,i); i++; usleep(10); } } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11662 Trac 1.4.3 viboes Wed, 23 Sep 2015 23:09:51 GMT component changed; owner set https://svn.boost.org/trac10/ticket/11662#comment:1 https://svn.boost.org/trac10/ticket/11662#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Sebastian Redl</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">property_tree</span> </li> </ul> Ticket