作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
<分区>
在没有同步的情况下在 2 个不同的线程中使用 map::empty 和 map::insert 是否安全?
void thread1()
{
...
while(running)
{
//get data from network
..........
std::lock_guard<std::mutex> lock(mtx);
map1.insert(data);
}
}
void thread2()
{
while(running || !map1.empty())
{
std::lock_guard<std::mutex> lock(mtx);
//remove outdated elements from map
......
}
}
我是一名优秀的程序员,十分优秀!