Question on lazy val
I was looking at the byte code generated for a lazy val, and had a few questions and comments. It appears to be implemented as basic DCL using a volatile int as flag and synchronizing on the class instance.
* The int flag does & operation for every access to lazy val. Why, and why not a simple boolean?
* Synchronization is on the enclosing instance. Is that deliberate? Worst case, it could cause a hard to find dead-lock. Could a synthetic monitor not be used to eliminate worst case, or am I missing some obvious reason?
Nils