You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reasons why we can safely remove volatile are:
Our primitives do aligned reading on all platforms (int 32 bit and boolean)
And the second, since we have all the fields of this class (x y z) immutable, therefore the race will not destroy anything for us
The solution, and yet you can step on a rake if you read from the heap several times, so we have to read 1 time, the final result of the hashCode should look like this:
@Override
public int hashCode() {
int h = hashCode; // read only ONCE
if (h == 0 && !hashed) {
h = calc Hash code
if (h == 0) {
hashed = true;
} else {
hashCode = h;
}
}
return h;
}
This will remove volatile on hashed and hashCode fields
The text was updated successfully, but these errors were encountered:
in the Vector Matrix classes etc we can observe 2 fields
The reasons why we can safely remove volatile are:
Our primitives do aligned reading on all platforms (int 32 bit and boolean)
And the second, since we have all the fields of this class (x y z) immutable, therefore the race will not destroy anything for us
The solution, and yet you can step on a rake if you read from the heap several times, so we have to read 1 time, the final result of the hashCode should look like this:
This will remove volatile on hashed and hashCode fields
The text was updated successfully, but these errors were encountered: