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

后端 未结 5 770
面向向阳花
面向向阳花 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 15:46

    If you implement a reader/writer solution, then you can have the writer set a flag that invalidates all the iterators of the readers.

    http://en.wikipedia.org/wiki/Readers-writer_lock

    I would not try to write to the map without synchronization, as Josh and Paul Tomblin mentioned.

提交回复
热议问题