Is there any advantage of declaring std::vector
as thread_local
?
like
static unique_ptr<std::vector<ObjectA>> vecVariable;
as declaring std::vector
as thread_local doesn't make its operations like pop_back()
and erase()
synchronized.
As in every STL container, If there is one thread modifying a container then there shall be no concurrent threads reading or writing the same container, so I can not do erase()
and pop_back()
on a vector
object in a concurrent/multithreaded environment.
Even if I declare vector as thread_local
, my code is crashing in one of the operations. I understand I may need to do these operations under lock, but I am just trying to understand when someone would define a std::vector
as thread_local
?