Thank you Alex and Ulrich!
****************************************************************
Suppose that vector has 5 elements and i = 3.
Following statement expects to update 4th element.
vector[i] = 2 * vector[i] + 1;
What actually may happen is:
vector[i] = // 4th element's reference is fetched.
// Then current thread is preemted and
// vector is emptied in other thread.
2 * vector[i] + 1; // Oops! vector is empty already
****************************************************************
If the code is like:
EnterCriticalSection();
vector[i] = 2 * vector[i] + 1;
LeaveCriticalSection();
Will the execution of the above be atomic?
Even though another thread may call "vector.empty()", will this problem be
solved by just doing this:
EnterCriticalSection();
vector.empty();
LeaveCriticalSection();
Is that good enough to say that doing the following will make using STL
classes thread-safe:
Whenever there is a writing operation from a thread (at least), all accesses
to a STL class as a whole, not just partial/single element(s), need to be
synchronized.