I am writing C++ multithreaded code using GCC C++ 20 on Intel Broadwell XEONs or AMD EPYC 7551s, Intel TBB, and Pagmo2 libraries for optimization problems. If I declare concurrent_vector X and the elements of X are concurrently modified by multiple running threads, I believe the operations would be thread-safe. Please kindly correct me if I’m wrong.
My real question is this: If multiple threads access the elements of X,i.e. more than one thread attempts to simultaneously modify an element of X, e.g. X.at(5), will the operation be atomic and lock-free or will there be a lock with significant performance consequences? Also, let’s say that thread 0 modifies X.at(i) while thread 1 simultaneously modifies X.at(j) with i != j. What will be the performance implications and will the operation be lock-free i.e. atomic?
I am new to concurrent C++, TBB and was not able to find a definitive, clear answer using a Google search.
I have searched Google and TBB documentation have not found a clear answer to the above yet. I’m not sure if TBB concurrent containers are actually atomic?