Do I need to synchronize?
Just wondering about this, if I want to do something like this in a thread, do I have to synchronize them?
Code:
(example 1)
//global vector
std::vector<Object> objects;
//main code
objects.back().doSomething();
//thread code
objects.pop_back();
(example 2)
//global vector
std::vector<Object> objects;
//main code
objects[0].move();
//thread code
objects[0].draw();
In example 1, is it possible for the object to get deleted before doSomething() completes?
And in example 2, is it possible that something will go screwy with the stack pointer or something (I don't really know what I'm talking about, and my books don't help) or is Windows smart enough to be sure everything happens properly?
In both examples, will I need to use a critical section or something related to ensure exclusive access to the vector? :confused: