亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內(nèi)置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數(shù)據(jù)結(jié)構(gòu)heap) container/list(容器數(shù)據(jù)結(jié)構(gòu)list) container/ring(容器數(shù)據(jù)結(jié)構(gòu)ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(數(shù)據(jù)庫/sql) database/sql/driver(數(shù)據(jù)庫/sql/driver) debug debug/dwarf(調(diào)試/dwarf) debug/elf(調(diào)試/elf) debug/gosym(調(diào)試/gosym) debug/macho(調(diào)試/macho) debug/pe(調(diào)試/pe) debug/plan9obj(調(diào)試/plan9obj) encoding encoding(編碼) encoding/ascii85(編碼/ascii85) encoding/asn1(編碼/asn1) encoding/base32(編碼/base32) encoding/base64(編碼/base64) encoding/binary(編碼/binary) encoding/csv(編碼/csv) encoding/gob(編碼/gob) encoding/hex(編碼/hex) encoding/json(編碼/json) encoding/pem(編碼/pem) encoding/xml(編碼/xml) errors errors(錯誤) expvar expvar flag flag(命令行參數(shù)解析flag包) fmt fmt go go/ast(抽象語法樹) go/build go/constant(常量) go/doc(文檔) go/format(格式) go/importer go/parser go/printer go/scanner(掃描儀) go/token(令牌) go/types(類型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(圖像) image/color(顏色) image/color/palette(調(diào)色板) image/draw(繪圖) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系統(tǒng)) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路徑) plugin plugin(插件) reflect reflect(反射) regexp regexp(正則表達式) regexp/syntax runtime runtime(運行時) runtime/debug(調(diào)試) runtime/internal/sys runtime/pprof runtime/race(競爭) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉(zhuǎn)換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調(diào)用) testing testing(測試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
characters

  • import "sync/atomic"

  • 概觀

  • 索引

  • 示例

概觀

Package atomic 提供了用于實現(xiàn)同步算法的低級原子內(nèi)存原語。

這些功能需要非常小心才能正確使用。除特殊的低級別應(yīng)用程序外,同步更適合使用頻道或同步軟件包的功能。通過溝通共享內(nèi)存; 不要通過共享內(nèi)存進行通信。

由 SwapT 函數(shù)實現(xiàn)的交換操作是以下原子等值:

old = *addr*addr = newreturn old

由 CompareAndSwapT 函數(shù)實現(xiàn)的比較和交換操作與以下原子等價:

if *addr == old {*addr = newreturn true}return false

由 Add T函數(shù)實現(xiàn)的 add 操作與以下操作相當:

*addr += deltareturn *addr

由 LoadT 和 StoreT 函數(shù)實現(xiàn)的加載和存儲操作是  "return *addr" and "*addr = val" 的原子等價物。

索引

  • func AddInt32(addr *int32, delta int32) (new int32)

  • func AddInt64(addr *int64, delta int64) (new int64)

  • func AddUint32(addr *uint32, delta uint32) (new uint32)

  • func AddUint64(addr *uint64, delta uint64) (new uint64)

  • func AddUintptr(addr *uintptr, delta uintptr) (new uintptr)

  • func CompareAndSwapInt32(addr *int32, old, new int32) (swapped bool)

  • func CompareAndSwapInt64(addr *int64, old, new int64) (swapped bool)

  • func CompareAndSwapPointer(addr *unsafe.Pointer, old, new unsafe.Pointer) (swapped bool)

  • func CompareAndSwapUint32(addr *uint32, old, new uint32) (swapped bool)

  • func CompareAndSwapUint64(addr *uint64, old, new uint64) (swapped bool)

  • func CompareAndSwapUintptr(addr *uintptr, old, new uintptr) (swapped bool)

  • func LoadInt32(addr *int32) (val int32)

  • func LoadInt64(addr *int64) (val int64)

  • func LoadPointer(addr *unsafe.Pointer) (val unsafe.Pointer)

  • func LoadUint32(addr *uint32) (val uint32)

  • func LoadUint64(addr *uint64) (val uint64)

  • func LoadUintptr(addr *uintptr) (val uintptr)

  • func StoreInt32(addr *int32, val int32)

  • func StoreInt64(addr *int64, val int64)

  • func StorePointer(addr *unsafe.Pointer, val unsafe.Pointer)

  • func StoreUint32(addr *uint32, val uint32)

  • func StoreUint64(addr *uint64, val uint64)

  • func StoreUintptr(addr *uintptr, val uintptr)

  • func SwapInt32(addr *int32, new int32) (old int32)

  • func SwapInt64(addr *int64, new int64) (old int64)

  • func SwapPointer(addr *unsafe.Pointer, new unsafe.Pointer) (old unsafe.Pointer)

  • func SwapUint32(addr *uint32, new uint32) (old uint32)

  • func SwapUint64(addr *uint64, new uint64) (old uint64)

  • func SwapUintptr(addr *uintptr, new uintptr) (old uintptr)

  • type Value

  • func (v *Value) Load() (x interface{})

  • func (v *Value) Store(x interface{})

  • 錯誤

示例

Value (Config) Value (ReadMostly)

打包文件

doc.go value.go

func AddInt32

func AddInt32(addr *int32, delta int32) (new int32)

AddInt32 自動地將增量添加到 * addr 并返回新值。

func AddInt64

func AddInt64(addr *int64, delta int64) (new int64)

AddInt64 自動地將增量添加到 * addr 并返回新值。

func AddUint32

func AddUint32(addr *uint32, delta uint32) (new uint32)

AddUint32 自動地將增量添加到 * addr 并返回新值。要從 x 中減去一個帶符號的正常數(shù)值 c ,請執(zhí)行 AddUint32(&x, ^uint32(c-1))。特別是,要減少 x ,請執(zhí)行 AddUint32(&x, ^uint32(0)) 。

func AddUint64

func AddUint64(addr *uint64, delta uint64) (new uint64)

AddUint64 自動地將增量添加到 * addr 并返回新值。要從 x 中減去一個帶符號的正常數(shù)值 c ,請執(zhí)行 AddUint64(&x, ^uint64(c-1))。特別是,要減少 x ,請執(zhí)行 AddUint64(&x, ^uint64(0)) 。

func AddUintptr

func AddUintptr(addr *uintptr, delta uintptr) (new uintptr)

AddUintptr 自動向 delta addr 添加 delta 并返回新值。

func CompareAndSwapInt32

func CompareAndSwapInt32(addr *int32, old, new int32) (swapped bool)

CompareAndSwapInt32 為 int32 值執(zhí)行比較和交換操作。

func CompareAndSwapInt64

func CompareAndSwapInt64(addr *int64, old, new int64) (swapped bool)

CompareAndSwapInt64 為 int64 值執(zhí)行比較和交換操作。

func CompareAndSwapPointer

func CompareAndSwapPointer(addr *unsafe.Pointer, old, new unsafe.Pointer) (swapped bool)

CompareAndSwapPointer 對不安全的指針值執(zhí)行比較和交換操作。

func CompareAndSwapUint32

func CompareAndSwapUint32(addr *uint32, old, new uint32) (swapped bool)

CompareAndSwapUint32 為 uint32 值執(zhí)行比較和交換操作。

func CompareAndSwapUint64

func CompareAndSwapUint64(addr *uint64, old, new uint64) (swapped bool)

CompareAndSwapUint64 為 uint64 值執(zhí)行比較和交換操作。

func CompareAndSwapUintptr

func CompareAndSwapUintptr(addr *uintptr, old, new uintptr) (swapped bool)

CompareAndSwapUintptr 為 uintptr 值執(zhí)行比較和交換操作。

func LoadInt32

func LoadInt32(addr *int32) (val int32)

LoadInt32 自動加載 * addr 。

func LoadInt64

func LoadInt64(addr *int64) (val int64)

LoadInt64 自動加載 * addr 。

func LoadPointer

func LoadPointer(addr *unsafe.Pointer) (val unsafe.Pointer)

LoadPointer atomically loads *addr.

func LoadUint32

func LoadUint32(addr *uint32) (val uint32)

LoadUint32 自動加載 * addr 。

func LoadUint64

func LoadUint64(addr *uint64) (val uint64)

LoadUint64 自動地加載 * addr 。

func LoadUintptr

func LoadUintptr(addr *uintptr) (val uintptr)

LoadUintptr 自動加載 * addr 。

func StoreInt32

func StoreInt32(addr *int32, val int32)

StoreInt32 自動地將 val 存儲到 * addr 中。

func StoreInt64

func StoreInt64(addr *int64, val int64)

StoreInt64 自動地將 val 存儲到 * addr 中。

func StorePointer

func StorePointer(addr *unsafe.Pointer, val unsafe.Pointer)

StorePointer 自動地將 val 存儲到 * addr 中。

func StoreUint32

func StoreUint32(addr *uint32, val uint32)

StoreUint32 自動地將 val 存儲到 * addr 中。

func StoreUint64

func StoreUint64(addr *uint64, val uint64)

StoreUint64 自動地將 val 存儲到 * addr 中。

func StoreUintptr

func StoreUintptr(addr *uintptr, val uintptr)

StoreUintptr 自動將 val 存儲到 * addr 中。

func SwapInt32

func SwapInt32(addr *int32, new int32) (old int32)

SwapInt32 將自動地新成員存儲到 * addr 并返回以前的 * addr 值。

func SwapInt64

func SwapInt64(addr *int64, new int64) (old int64)

SwapInt64 自動地將新的值存儲到 * addr 并返回前一個 * addr 值。

func SwapPointer

func SwapPointer(addr *unsafe.Pointer, new unsafe.Pointer) (old unsafe.Pointer)

SwapPointer 自動地將新的值存儲到 * addr 并返回以前的 * addr 值。

func SwapUint32

func SwapUint32(addr *uint32, new uint32) (old uint32)

SwapUint32 自動地將新的值存儲到 * addr 并返回前一個 * addr 值。

func SwapUint64

func SwapUint64(addr *uint64, new uint64) (old uint64)

SwapUint64 自動地將新的值存儲到 * addr 中,并返回以前的 * addr 值。

func SwapUintptr

func SwapUintptr(addr *uintptr, new uintptr) (old uintptr)

SwapUintptr 自動地將新值存儲到 * addr 中,并返回前一個 * addr 值。

type Value

值提供了一個自動加載和一個一致的類型值的存儲。Value 的零值從 Load 返回 nil 。一旦 Store 被調(diào)用,Value 不能被復制。

首次使用后不得復制 Value 。

type Value struct {        // contains filtered or unexported fields}

示例(配置)

以下示例顯示如何使用 Value 進行周期性程序配置更新以及將更改傳播到工作程序。

編碼:

var config Value // holds current server configuration// Create initial config value and store into config.config.Store(loadConfig())go func() {        // Reload config every 10 seconds        // and update config value with the new version.        for {
                time.Sleep(10 * time.Second)
                config.Store(loadConfig())        }}()// Create worker goroutines that handle incoming requests// using the latest config value.for i := 0; i < 10; i++ {
        go func() {                for r := range requests() {
                        c := config.Load()                        // Handle request r using config c.
                        _, _ = r, c                }        }()}

示例(ReadMostly)

以下示例說明如何使用寫入時復制習慣用法維護可擴展的經(jīng)常讀取但不經(jīng)常更新的數(shù)據(jù)結(jié)構(gòu)。

編碼:

type Map map[string]stringvar m Value
m.Store(make(Map))var mu sync.Mutex // used only by writers// read function can be used to read the data without further synchronizationread := func(key string) (val string) {
        m1 := m.Load().(Map)        return m1[key]}// insert function can be used to update the data without further synchronizationinsert := func(key, val string) {
        mu.Lock() // synchronize with other potential writers
        defer mu.Unlock()
        m1 := m.Load().(Map) // load current value of the data structure
        m2 := make(Map)      // create a new value        for k, v := range m1 {
                m2[k] = v // copy all data from the current object to the new one        }
        m2[key] = val // do the update that we need
        m.Store(m2)   // atomically replace the current object with the new one        // At this point all new readers start working with the new version.        // The old version will be garbage collected once the existing readers        // (if any) are done with it.}_, _ = read, insert

func (*Value) Load

func (v *Value) Load() (x interface{})

Load 返回最近的存儲設(shè)置的值。如果此值沒有存儲調(diào)用,則返回 nil 。

func (*Value) Store

func (v *Value) Store(x interface{})

Store 將 Value 的值設(shè)置為 x 。對于給定值的所有對 Store的調(diào)用都必須使用相同具體類型的值。存儲不一致的類型恐慌,就像 Store(nil) 一樣。

錯誤

  • ?   在x86-32上,64位函數(shù)使用 Pentium MMX 之前不可用的指令。

在非 Linux ARM 上,64位函數(shù)使用 ARMv6k 內(nèi)核之前不可用的指令。

在 ARM 和 x86-32 上,調(diào)用者都有責任安排自動訪問64位字的64位對齊方式。變量或分配的結(jié)構(gòu),數(shù)組或片中的第一個字可以依賴于64位對齊。

Previous article: Next article: