3 ms·
There is simple rule for that: do not touch shared state outside of relevant critical section. To some extent the cited problem is unique to Java, because the
by dfox 9y ago
There is simple rule for that: do not touch shared state outside of relevant critical section.
To some extent the cited problem is unique to Java, because the whole monitor concept just creates confusion about what synchronized really means (and also creates significant overhead by making literally everything usable as mutex). Pretty common misconception is that synchronized is akin to some kind of read-write lock (in which case the code above would work as expected).