package MemoryConsistencyErrorExample;
public class MemoryConsistencyErrorExample {
    private static int counter = 0; 

    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> incrementCounter());
        Thread thread2 = new Thread(() -> incrementCounter());
        Thread thread3 = new Thread(() -> incrementCounter());

        thread1.start();
        thread2.start();
        thread3.start();

        try {
            thread1.join();
            thread2.join();
            thread3.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("최종 카운터 값: " + counter);
    }

    private static void incrementCounter() {
        for (int i = 0; i < 1000000; i++) {
            counter++;
        }
    }
}
