package thead.safe.safe0;

import lombok.Getter;

@Getter
public class UnsafeCounter {
    private static Integer count = 0;

    public static void main(String[] args) throws InterruptedException {
        // 创建 1000 个线程并进行计数
        Thread[] threads = new Thread[1000];
        for (int i = 0; i < 1000; i++) {
            threads[i] = new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    count++;
                }
            });
            threads[i].start();
        }

        // 等待所有线程完成
        for (int i = 0; i < 1000; i++) {
            threads[i].join();
        }

        // 输出最终计数值
        System.out.println("Count: " + count);  // 结果应该等于 1000000
    }
}
