The development of a Java VM for .NET
I worked on java.lang.Thread and ran into two issues. In .NET it is not possible to:
I worked around the interrupted status issue by always returning false when you query a thread other than the current thread :-( and to test for Monitor ownership I do a Monitor.Wait on the object, with a timeout of 0. That works, but it isn't safe, because Wait temporarily releases the Monitor (if we do own it), and that could cause a deadlock :-(
The proposal gives the same "solution" to the holdsLock() not implemented problem. But I hadn't realized that wait() could of course give up the lock. Bad... A better "solution" could then be calling notify() on the object. Then you don't loose the lock and correctly written code (that does a wait in a while(!condition) loop) keeps working correctly.
I don't like using notify(), because I'm sure there is a lot of code that depends on notify not being spurious (I've written at least a few classes that depend on that). I just re-read the documentation and I don't believe it is allowed to notify an object, if you don't mean it.
Regarding the interrupted flag, I did consider that, but for my specific VM that still leaves the problem that a thread can be interrupted from .NET code, and that wouldn't set the flag.
Remember Me
I apologize for the lameness of this, but the comment spam was driving me nuts. In order to be able to post a comment, you need to answer a simple question. Hopefully this question is easy enough not to annoy serious commenters, but hard enough to keep the spammers away.
Anti-Spam Question: What method on java.lang.System returns an object's original hashcode (i.e. the one that would be returned by java.lang.Object.hashCode() if it wasn't overridden)? (case is significant)