Is there any way to check if an iterator is valid?

后端 未结 5 771
面向向阳花
面向向阳花 2021-01-06 15:21

For two threads manipulating a container map for example, what the correct way to test whether an iterator still valid (for performance reason) ?
Or would be of only in

5条回答
  •  粉色の甜心
    2021-01-06 16:07

    std::maps are not at all thread-safe. You'll end up with much worse problems than invalidated iterators, if you have more than one thread at a time modifying the same map. I don't even think you have a guarantee that you can read anything out of a map while it's being modified by another thread.

    Some pages on the STL and threading:

    • MSDN
    • SGI
    • GCC

提交回复
热议问题