首次提交:初始化项目代码

This commit is contained in:
sunct
2026-07-31 15:18:32 +08:00
commit d6393266b0
193 changed files with 14287 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
// bulma/atomic_value_trap.go
package main
import (
"fmt"
"sync/atomic"
)
func main() {
var v atomic.Value
v.Store("initial string") // 首次存储 string
// ❌ 错误:尝试存储不同类型的值(会 panic!)
defer func() {
if r := recover(); r != nil {
fmt.Println("⚠️ 捕获 panic:", r)
fmt.Println("✅ 正确做法:始终存储相同类型(推荐指针)")
}
}()
v.Store(123) // 运行时 panic: sync/atomic: store of inconsistently typed value into Value
}