unordered_map thread safety

后端 未结 7 709
故里飘歌
故里飘歌 2020-11-30 02:12

I am changing a single thread program into multi thread using boost:thread library. The program uses unordered_map as a hasp_map for lookups. My question is..

At on

7条回答
  •  無奈伤痛
    2020-11-30 03:02

    std::unordered_map meets the requirements of Container (ref http://en.cppreference.com/w/cpp/container/unordered_map). For container thread safety see: http://en.cppreference.com/w/cpp/container#Thread_safety.

    Important points:

    • "Different elements in the same container can be modified concurrently by different threads"
    • "All const member functions can be called concurrently by different threads on the same container. In addition, the member functions begin(), end(), rbegin(), rend(), front(), back(), data(), find(), lower_bound(), upper_bound(), equal_range(), at(), and, except in associative containers, operator[], behave as const for the purposes of thread safety (that is, they can also be called concurrently by different threads on the same container)."

提交回复
热议问题