Probably not. The problem is not vec-> size (), it is also in all other functions.
Consider this: vector :: size () is usually computed directly from elements, for example. .end - .begin . Now what happens with push_back in one thread? This affects the size, obviously, through the members. He changes memory. But there is no memory barrier. Other threads on other cores will just see the old memory. As a result, when they call size() , it will be calculated using the old values.
The obvious exception is that after creating the threads, the vector does not change size. Threads will never have outdated information.
source share