package fr.uge.concurrence.td02;

public class StopThreadBug implements Runnable {
    private boolean stop = false;

    public void stop() {
        stop = true;
    }

    @Override
    public void run() {
        while (!stop) {
            IO.println("Up");
        }
        IO.print("Done");
    }

    public static void main(String[] args) throws InterruptedException {
        var stopThreadBug = new StopThreadBug();
        Thread.ofPlatform().start(stopThreadBug::run);
        try {  
            Thread.sleep(5_000);    
        } catch (InterruptedException e) {
            throw new AssertionError();
        }
        IO.println("Trying to tell the thread to stop");
        stopThreadBug.stop();
    }
}
