commit
commit
7ae7e88856
|
@ -0,0 +1,29 @@
|
|||
public class MemoryBarrierTest extends Thread {
|
||||
Thread ikke;
|
||||
public boolean stopped = false;
|
||||
|
||||
public void stopRequest() {
|
||||
this.stopped = true;
|
||||
if (this.ikke != null) {
|
||||
this.ikke.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.ikke = Thread.currentThread();
|
||||
while (!this.stopped) {
|
||||
//this.ikke
|
||||
}
|
||||
System.out.println("MemoryBarrierTest-Thread actually stopped.");
|
||||
}
|
||||
|
||||
public static void main(String... args) throws InterruptedException {
|
||||
var t = new MemoryBarrierTest();
|
||||
t.start();
|
||||
Thread.sleep(1000);
|
||||
t.stopped = true;
|
||||
System.out.println("Main thread set stopped on MemoryBarrierTest-Thread.");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
public class MemoryBarrierTest2 extends Thread {
|
||||
|
||||
public volatile boolean stopped = false;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (!this.stopped) {
|
||||
}
|
||||
System.out.println("MemoryBarrierTest-Thread actually stopped.");
|
||||
}
|
||||
|
||||
public static void main(String... args) throws InterruptedException {
|
||||
var t = new MemoryBarrierTest2();
|
||||
t.start();
|
||||
Thread.sleep(1000);
|
||||
t.stopped = true;
|
||||
System.out.println("Main thread set stopped on MemoryBarrierTest-Thread.");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue