I have 2 threads.
The first one calls this function
public int doCompute1(obj)
{
if (obj.state == OK_FOR_COMPUTE1)
{
// do something
obj.state = OK_FOR_COMPUTE2;
}
}
The second thread calls this function
public int doCompute2(obj)
{
if (obj.state == OK_FOR_COMPUTE2)
{
// do something
obj.state = OK_FOR_COMPUTE1;
}
}
For the moment it seems to work perfectly !
My question is: Is it correct ?
Is it possible that on multicore processor, obj.state is in cache memory and then modifiyng this vaue by a thread, wouldn’t be visible by the second thread?
What should I do if this code is not correct?
will do the stuff
EDIT:
What synchronized do?