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

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
+29
View File
@@ -0,0 +1,29 @@
// bulma/atomic_pointer.go
package main
import (
"fmt"
"sync/atomic"
)
type Node struct {
Value int
Next *Node
}
func main() {
var head atomic.Pointer[Node]
head.Store(&Node{Value: 10})
// 原子替换头节点
old := head.Swap(&Node{Value: 20})
fmt.Printf("✅ 旧头节点值: %d\n", old.Value)
fmt.Printf("✅ 新头节点值: %d\n", head.Load().Value)
// CAS 安全更新(仅当当前值为预期时才更新)
if head.CompareAndSwap(&Node{Value: 20}, &Node{Value: 30}) {
fmt.Println("✅ CAS 成功:头节点更新为 30")
} else {
fmt.Println("❌ CAS 失败:头节点已被其他 goroutine 修改")
}
}