Go标准库

Posted by PanJinhao on May 4, 2024

atomic模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import "atomic"
atomic {
	AddType(addr *Type,delta Type) new Type
    相当于:*addr+=delta=>*addr
	CompareAndSwapType(addr *Type,old,new Type) bool
	相当于:
    if *addr==old {
        *addr=new
    }
	LoadType(addr *Type) val Type
    相当于:=>*addr
    StoreType(addr *Type,val Type)
    相当于:*addr=val
	SwapType(addr *Type,new Type) old Type
    相当于:old=*addr *addr=new => old
}
atomic.Type{} {
	.Add()
	.CompareAndSwap()
    .Load()
    .Store()
	.Swap()
}