2

Let's say I have an object threadWork initialised as:

vector< vector<myType> > threadWork(N_THREADS, vector<myType>());

I then deploy N_THREADS threads, each performing writes via vector::push_back()s to a separate element (its own vector<myType> object) of threadWork.

One thread then calls vector::clear() on its element of threadWork. Does this invalidate the writes of the other threads to their element? i.e Can vector::clear() called on one element of threadWork alter the memory allocation of the other elements of threadWork, such that a thread may be writing to invalid addresses as a result?

izaak_pyzaak
  • 930
  • 8
  • 23

1 Answers1

1

This is completely fine. Altering an element of the outer vector does not affect the other elements in any way.

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182