main
2wenty1ne 2024-10-15 15:32:52 +02:00
commit 7ae7e88856
2 changed files with 48 additions and 0 deletions

View File

@ -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.");
}
}

View File

@ -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.");
}
}