class myClass
{
int a, b;
void A() {...}
void B() {...}
};
myClass myObject;
If I make an object of myClass
called myObject
which has methods A
and B
, is it thread safe to call myObject's A
from one thread and its B
from another thread? Assuming A
and B
don't share any objects or access the same part of memory. What about accessing different members of myObject
like a
and b
?
Is it the same in Java and C++?
As far as I understand, a program is thread safe as long as different threads don't access the same part of memory at the same time. Here I pass myObject's reference to both threads but they are accessing different methods and members which ultimately have different addresses.