5 ms·
Can you explain what makes it so terrible? At first glance it seems as if it is thread safe, and avoiding synchronization locks can provide a nice speed up. Th
by conroe64 13y ago
Can you explain what makes it so terrible? At first glance it seems as if it is thread safe, and avoiding synchronization locks can provide a nice speed up.
The notion that currentPos could be set to the new Point before the Point(int x, int y) constructor completed was completely surprising to me.
Is that something that was obvious to you, or do you have other reasons to dislike it?
- hexagonc 13y agoYeah, this is very surprising to me. I simply didn't know that java worked that way and I've been programming in java for many years. I assumed that the memory that "currentPos" would eventually be bound to was fully initialized before the assignment operator remapped "currentPos" to the new value. I also assumed that binding a variable name to a new value is atomic across all threads.
- jlarocco 13y agocurrentPos is modified in one thread and read in a different thread, outside of a synchronized block, and without being protected by a mutex. It's a pretty straightforward recipe for disaster.