I have been reading different things on multithreading, C++, proper synchronization and locks to prevent race conditions. One question has not been answered for me, however: Is there a mutex required if I create an object in thread A, but use it exclusively in thread B afterwards?
In other words, I know that I don't need a mutex to prevent race conditions - do I need a mutex to serve as a memory barrier (or other potential problems)?
A very basic example to visualize what I mean
struct Object {
void do_stuff();
};
Object o;
std::thread worker_thread([&o](){
while (alive)
o.do_stuff();
}).join();
// `o` is never used outside worker_thread
I would be happy if you could also recommend me articles / books where I can read more into this topic and/or the right keywords to search for these kinds of scenarios.