jjzjj

SharedQueue

全部标签

c++ - 为什么 std::queue 不是线程安全的?

主题说明了这一点。我不明白为什么std::queue(或一般来说:任何队列)本质上不是线程安全的,当没有像其他数据结构那样涉及迭代器时。根据一般规律至少有一个线程正在写入...另一个线程正在读取共享资源我应该在以下示例代码中遇到冲突:#include"stdafx.h"#include#include#includestructresponse{staticint&getCount(){staticinttheCount=0;returntheCount;}intid;};std::queuequeue;//generate100responseobjectsandpushthemin