As much as I would be happy to rule that programs that
sleep in a loop without synchronization and expect to see
changes are just wrong, I think this may be the
one area where the strongest reeducation campaign is
needed.
>From Sun's demo programs included with jdk1.3 beta:
Here is the code from demo/applet/Blink/Blink.java
Thread blinker = null; // The thread that displays images
public void run() {
Thread me = Thread.currentThread();
while (blinker == me) {
try {
Thread.currentThread().sleep(delay);
}
catch (InterruptedException e) {
}
repaint();
}
}
public void stop() {
blinker = null;
}
The identical idiom appears in:
applet/Animator/Animator.java
applet/Clock/Clock2.java
applet/Fractal/CLSFractal.java
applet/GraphLayout/Graph.java
applet/NervousText/NervousText.java
Very similar idioms (that would also fail) appear in:
jfc/Java2D/src/RunWindow.java
jfc/Java2D/src/Intro.java
jfc/Java2D/src/DemoSurface.java
jfc/Java2D/src/MemoryMonitor.java
jfc/Java2D/src/PerformanceMonitor.java
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:20 EDT