Does tbb::concurrent_unordered_map::unsafe_erase invalidate any existing iterators?
Asked Answered
W

1

6

I see that tbb::concurrent_unordered_map hews pretty close to std::unordered_map while being safe for concurrency. I also know that unsafe_erase is not concurrent-safe with insert etc. The iterator docs also state that any existing iterators are still valid with insert, find etc.

The question is, does unsafe_erase invalidate any other iterator than the one it is asked to erase?

std::unordered_map and std::map certainly have this behavior, but it's not specified in the concurrent_unordered_map docs anywhere.

Weswesa answered 7/11, 2013 at 3:34 Comment(0)
H
6

tbb::unsafe_erase does not invalidate other iterators. This is a property that we should document.

The reason that it does not invalidate other iterators is that the underlying implementation is a split-ordered list, and an iterator just points into that list.

Hyperploid answered 7/11, 2013 at 17:3 Comment(1)
Thanks for a definitive answer. I was intending to use it for a cache, together with a queue of map iterators to determine the oldest entry to expire. Obviously if erasing the oldest entry would invalidate the queue, I would end up having to refresh the queue for every erasure or use a key instead.Weswesa

© 2022 - 2024 — McMap. All rights reserved.