// valhalla/build/fastdebug/jdk/bin/javac --enable-preview -source 26 --add-exports java.base/jdk.internal.vm.annotation=ALL-UNNAMED StrictInitTest.java && while valhalla/build/fastdebug/jdk/bin/java --enable-preview --add-exports java.base/jdk.internal.vm.annotation=ALL-UNNAMED -Xint StrictInitTest; do :; done;

import jdk.internal.vm.annotation.Strict;

public class StrictInitTest {
    static A shared = new A();

    static class A {
        @Strict
        final int x;

        A() {
            x = 1;
            super();
            shared = this;
        }
    }

    public static void main(String[] args) throws Exception {
        Thread reader = new Thread(() -> {
            for (int i = 0; i < 100_000; ++i) {
                int x = shared.x;
                if (x != 1) {
                    System.out.println("Observed: x = " + x);
                    System.exit(1);
                }
            }
        });

        Thread writer = new Thread(() -> {
            for (int i = 0; i < 100_000; ++i) {
                new A();
            }
        });

        reader.start();
        writer.start();
        reader.join();
        writer.join();
    }
}

