I have several objects needed to perform actions from different threads in C ++. I knew that it was necessary to block any variable that could be used by more than one thread at a time, but what if each thread accessed (written) to another data member of the same object? For example, each thread invokes a different method of the object, and not one of the methods called modification of the same data element. Is it safe until I get access to the same data item or do I need to lock the entire object?
I looked through the explanations and details on this topic, but each example seems to focus on single variables or non-member functions.
To summarize: Can I safely access 2 different data elements of the same object from 2 different threads without placing a lock on the whole object?
source
share