小编gj1*_*j13的帖子

从另一个线程插入/擦除时,我可以访问C++ 11 std :: map条目吗?

我可以访问(不锁定)std :: map条目而另一个线程插入/删除entrys吗?

示例伪C++:

typedef struct {
   int value;
   int stuff;
}some_type_t;

std::map<char,some_type_t*> my_map;   

//thread 1 does:
my_map.at('a')->value = 1;

//thread 2 does:
some_type_t* stuff = my_map.at('b');

//thread 3 does:
my_map.erase('c');

//I'm not modifying any elements T is a pointer to an previously allocated "some_type_t" 
Run Code Online (Sandbox Code Playgroud)

std C++ 11说所有成员都应该是线程安全的(erase()不是const).

c++ multithreading stdmap c++11

5
推荐指数
2
解决办法
1004
查看次数

标签 统计

c++ ×1

c++11 ×1

multithreading ×1

stdmap ×1