Can I access a C++11 std::map entry while inserting/erasing from another thread?

前端 未结 4 1170
半阙折子戏
半阙折子戏 2021-01-12 15:16

Can I access (without locking) an std::map entry while another thread inserts/erases entrys?

example pseudo C++:

typedef struct {
   int value;
   in         


        
4条回答
  •  旧巷少年郎
    2021-01-12 16:14

    As long as the threads are not accessing the same address at the same time there will be no problem.

    But for a direct answer to your question, no, it is not thread safe so you can't do it without locking without any errors.

提交回复
热议问题