首页 > 其他 > 详细

Golang atomic

时间:2017-12-22 15:25:57      阅读:289      评论:0      收藏:0      [点我收藏+]

原子操作函数

分为下面系列函数,其中Xxx可以是Int32/Int64/Uint32/Uint64/Uintptr/Pointer其中一种。

 

1.SwapXxx系列:交换新旧值;

// SwapInt32 atomically stores new into *addr and returns the previous *addr value.
func SwapInt32(addr *int32, new int32) (old int32)

 

2.CompareAndSwapXxx系列:比较并交换;

// CompareAndSwapInt32 executes the compare-and-swap operation for an int32 value.
func CompareAndSwapInt32(addr *int32, old, new int32) (swapped bool)

 

3.AddXxx系列:加减;

// AddInt32 atomically adds delta to *addr and returns the new value.
func AddInt32(addr *int32, delta int32) (new int32)

 

4.LoadXxx系列:读取;

// LoadInt32 atomically loads *addr.
func LoadInt32(addr *int32) (val int32)

 

5.StoreXxx系列:保存;

// StoreInt32 atomically stores val into *addr.
func StoreInt32(addr *int32, val int32)

 

以上。

 

Golang atomic

原文:http://www.cnblogs.com/chevin/p/8086049.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!