Problems with java Thread
807569Sep 20 2006 — edited Sep 22 2006I'm reading book "JAVA THREAD" published by OREILLY.
And on fifth chapter, it gives an example.
one Thread's two method:
private boolean done = false;
public void run()
{
while(!done)
{
foo();
}
}
public void setDone()
{
done = true;
}
it says, the run method will be compiled as machine code:
Begin method run
load register r1 with memory location 0xff12345
Label L1:
Test if register r1 == 1
If true branch to L2
Call method foo
Branch to L1
Label L2:
End method run
setDone method will be compiled like:
Begin method setDone
Store 1 into memory location 0xff12345
End method setDone
And it says " because Run method will never reload 0xff12345 to register r1(in while loop), so setDone method will never lead to run stop.
I'm so puzzled with this. I have test this code on windows platform, run method can stop after another Thread call setDone method !.
but I think "JAVA THREAD" should have error on this, so why ?