- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I have a vector that will be accessed by multiple threads, no creation or destruction, or even grow size will happen during multi-threading. Which one should I choose, a std::vector of atomic type, or concurrent_vector?
In other words, only the overloaded [] will be used to update and then read function will be called.
Thanks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
concurrent_vector allows concurrent growth and guarantees that elements, once allocated, will stay in place, but it does not change anything about how each of them is used, so a std::vector should suffice in your situation. Whether you want a vector of atomics depends on whether you would use an atomic if there were only a single element: if your algorithm can avoid races by separating the writing and the reading (including proper synchronisation), you don't need an atomic, otherwise you do, but consider carefully as this is not a common situation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. But concurrent_vector does have thread-safe feature(lock) for access (like using [] ), right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can have a race on any particular element with tbb::concurrent_vector just as with std::vector.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page