R. Clayton (rclayton@monmouth.edu)
(no date)
Using simple spin-lock synchronization
while (carWait[id]) { }
in Java is not a good idea. The JVM does not require that threads be scheduled
in such a way as to make simple spin locks behave properly. In particular,
simple spin locks do not work on Sun's JVM.
There are spin-lock implementations that will work on any correctly implemented
JVM, but they are expensive to use (as is any spin lock on uniprocessor
systems). It is better (more portable and efficient) to implement
synchronization using Java's primitives (synchronized blocks and
wait-notify-notifyAll), preferably by using them to create higher-level
synchronization mechanisms.
I'll have more to say about this in tomorrow's lecture.
This archive was generated by hypermail 2.0b3 on Tue Aug 12 2003 - 09:30:05 EDT