terminate called after throwing an instance of 'Json::LogicError'
demo:
std::queue<Json::Value> _queue;
// thread1:
Json::Value root;
root["Name"] = "Lucy";
_queue.push(root);
// thread2:
Json::Value root =_queue.pop();
if(root["Name"].isString()){
//....
}
root["Name"] cause core dump
terminate called after throwing an instance of 'Json::LogicError' what(): in Json::Value::resolveReference(key, end): requires objectValue
The demo is pretty incomplete @xuejun88. I can't tell if thread1 and thread2 are looping. I also can't tell whether thread2 is checking the _queue before performing a .pop.
You haven't mentioned how you're synchronizing access to the _queue among your threads here. std::queue is not a multi-thread-safe container. You have to supply some locking around it. Also, its pop() member returns void, so you're not giving an accurate picture here.
If you're mid-pop and another thread comes along an does a simultaneous push, I wouldn't expect this to be successful. I believe what you're getting is undefined behavior related to racing accesses to the _queue.
我遇到了相同的问题,请问你有什么解决方案嘛