package main

import (
	"fmt"
	"sync/atomic"
	"time"
)

func main() {
	var stop int32 = 0

	go func() {
		for atomic.LoadInt32(&stop) == 0 {
			// 忙等：什么也不干，不让出 CPU
		}
		fmt.Println("worker 退出")
	}()

	time.Sleep(2 * time.Second)
	fmt.Println("main: 设置 stop=1")
	atomic.StoreInt32(&stop, 1)

	time.Sleep(1 * time.Second)
}
