Movatterモバイル変換


[0]ホーム

URL:


atomic

packagestandard library
go1.25.2Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2025 License:BSD-3-ClauseImports:2Imported by:0

Details

Repository

cs.opensource.google/go/go

Links

Documentation

Overview

Package atomic provides atomic operations, independent of sync/atomic,to the runtime.

On most platforms, the compiler is aware of the functions definedin this package, and they're replaced with platform-specific intrinsics.On other platforms, generic implementations are made available.

Unless otherwise noted, operations defined in this package are sequentiallyconsistent across threads with respect to the values they manipulate. Morespecifically, operations that happen in a specific order on one thread,will always be observed to happen in exactly that order by another thread.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcAnd

func And(ptr *uint32, valuint32)

funcAnd32

func And32(ptr *uint32, valuint32)uint32

funcAnd64

func And64(ptr *uint64, valuint64)uint64

funcAnd8

func And8(ptr *uint8, valuint8)

funcAnduintptr

func Anduintptr(ptr *uintptr, valuintptr)uintptr

funcCas

func Cas(ptr *uint32, old, newuint32)bool

funcCas64

func Cas64(ptr *uint64, old, newuint64)bool

funcCasRel

func CasRel(ptr *uint32, old, newuint32)bool

funcCasint32

func Casint32(ptr *int32, old, newint32)bool

funcCasint64

func Casint64(ptr *int64, old, newint64)bool

funcCasp1

func Casp1(ptr *unsafe.Pointer, old, newunsafe.Pointer)bool

NO go:noescape annotation; see atomic_pointer.go.

funcCasuintptr

func Casuintptr(ptr *uintptr, old, newuintptr)bool

funcLoad

func Load(ptr *uint32)uint32

funcLoad64

func Load64(ptr *uint64)uint64

funcLoad8

func Load8(ptr *uint8)uint8

funcLoadAcq

func LoadAcq(ptr *uint32)uint32

funcLoadAcq64

func LoadAcq64(ptr *uint64)uint64

funcLoadAcquintptr

func LoadAcquintptr(ptr *uintptr)uintptr

funcLoadint32

func Loadint32(ptr *int32)int32

funcLoadint64

func Loadint64(ptr *int64)int64

funcLoaduint

func Loaduint(ptr *uint)uint

funcLoaduintptr

func Loaduintptr(ptr *uintptr)uintptr

funcOr

func Or(ptr *uint32, valuint32)

funcOr32

func Or32(ptr *uint32, valuint32)uint32

funcOr64

func Or64(ptr *uint64, valuint64)uint64

funcOr8

func Or8(ptr *uint8, valuint8)

funcOruintptr

func Oruintptr(ptr *uintptr, valuintptr)uintptr

funcStore

func Store(ptr *uint32, valuint32)

funcStore64

func Store64(ptr *uint64, valuint64)

funcStore8

func Store8(ptr *uint8, valuint8)

funcStoreRel

func StoreRel(ptr *uint32, valuint32)

funcStoreRel64

func StoreRel64(ptr *uint64, valuint64)

funcStoreReluintptr

func StoreReluintptr(ptr *uintptr, valuintptr)

funcStoreint32

func Storeint32(ptr *int32, newint32)

funcStoreint64

func Storeint64(ptr *int64, newint64)

funcStorepNoWB

func StorepNoWB(ptrunsafe.Pointer, valunsafe.Pointer)

StorepNoWB performs *ptr = val atomically and without a writebarrier.

NO go:noescape annotation; see atomic_pointer.go.

funcStoreuintptr

func Storeuintptr(ptr *uintptr, newuintptr)

funcXadd

func Xadd(ptr *uint32, deltaint32)uint32

funcXadd64

func Xadd64(ptr *uint64, deltaint64)uint64

funcXaddint32

func Xaddint32(ptr *int32, deltaint32)int32

funcXaddint64

func Xaddint64(ptr *int64, deltaint64)int64

funcXadduintptr

func Xadduintptr(ptr *uintptr, deltauintptr)uintptr

funcXchg

func Xchg(ptr *uint32, newuint32)uint32

funcXchg64

func Xchg64(ptr *uint64, newuint64)uint64

funcXchg8added ingo1.24.0

func Xchg8(ptr *uint8, newuint8)uint8

funcXchgint32

func Xchgint32(ptr *int32, newint32)int32

funcXchgint64

func Xchgint64(ptr *int64, newint64)int64

funcXchguintptr

func Xchguintptr(ptr *uintptr, newuintptr)uintptr

Types

typeBool

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

Bool is an atomically accessed bool value.

A Bool must not be copied.

func (*Bool)Load

func (b *Bool) Load()bool

Load accesses and returns the value atomically.

func (*Bool)Store

func (b *Bool) Store(valuebool)

Store updates the value atomically.

typeFloat64

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

Float64 is an atomically accessed float64 value.

8-byte aligned on all platforms, unlike a regular float64.

A Float64 must not be copied.

func (*Float64)Load

func (f *Float64) Load()float64

Load accesses and returns the value atomically.

func (*Float64)Store

func (f *Float64) Store(valuefloat64)

Store updates the value atomically.

typeInt32

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

Int32 is an atomically accessed int32 value.

An Int32 must not be copied.

func (*Int32)Add

func (i *Int32) Add(deltaint32)int32

Add adds delta to i atomically, returningthe new updated value.

This operation wraps around in the usualtwo's-complement way.

func (*Int32)CompareAndSwap

func (i *Int32) CompareAndSwap(old, newint32)bool

CompareAndSwap atomically compares i's value with old,and if they're equal, swaps i's value with new.It reports whether the swap ran.

func (*Int32)Load

func (i *Int32) Load()int32

Load accesses and returns the value atomically.

func (*Int32)Store

func (i *Int32) Store(valueint32)

Store updates the value atomically.

func (*Int32)Swap

func (i *Int32) Swap(newint32)int32

Swap replaces i's value with new, returningi's value before the replacement.

typeInt64

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

Int64 is an atomically accessed int64 value.

8-byte aligned on all platforms, unlike a regular int64.

An Int64 must not be copied.

func (*Int64)Add

func (i *Int64) Add(deltaint64)int64

Add adds delta to i atomically, returningthe new updated value.

This operation wraps around in the usualtwo's-complement way.

func (*Int64)CompareAndSwap

func (i *Int64) CompareAndSwap(old, newint64)bool

CompareAndSwap atomically compares i's value with old,and if they're equal, swaps i's value with new.It reports whether the swap ran.

func (*Int64)Load

func (i *Int64) Load()int64

Load accesses and returns the value atomically.

func (*Int64)Store

func (i *Int64) Store(valueint64)

Store updates the value atomically.

func (*Int64)Swap

func (i *Int64) Swap(newint64)int64

Swap replaces i's value with new, returningi's value before the replacement.

typePointer

type Pointer[Tany] struct {// contains filtered or unexported fields}

Pointer is an atomic pointer of type *T.

func (*Pointer[T])CompareAndSwap

func (p *Pointer[T]) CompareAndSwap(old, new *T)bool

CompareAndSwap atomically (with respect to other methods)compares u's value with old, and if they're equal,swaps u's value with new.It reports whether the swap ran.

func (*Pointer[T])CompareAndSwapNoWB

func (p *Pointer[T]) CompareAndSwapNoWB(old, new *T)bool

CompareAndSwapNoWB atomically (with respect to other methods)compares u's value with old, and if they're equal,swaps u's value with new.It reports whether the swap ran.

WARNING: As the name implies this operation does *not*perform a write barrier on value, and so this operation mayhide pointers from the GC. Use with care and sparingly.It is safe to use with values not found in the Go heap.Prefer CompareAndSwap instead.

func (*Pointer[T])Load

func (p *Pointer[T]) Load() *T

Load accesses and returns the value atomically.

func (*Pointer[T])Store

func (p *Pointer[T]) Store(value *T)

Store updates the value atomically.

func (*Pointer[T])StoreNoWB

func (p *Pointer[T]) StoreNoWB(value *T)

StoreNoWB updates the value atomically.

WARNING: As the name implies this operation does *not*perform a write barrier on value, and so this operation mayhide pointers from the GC. Use with care and sparingly.It is safe to use with values not found in the Go heap.Prefer Store instead.

typeUint32

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

Uint32 is an atomically accessed uint32 value.

A Uint32 must not be copied.

func (*Uint32)Add

func (u *Uint32) Add(deltaint32)uint32

Add adds delta to u atomically, returningthe new updated value.

This operation wraps around in the usualtwo's-complement way.

func (*Uint32)And

func (u *Uint32) And(valueuint32)

And takes value and performs a bit-wise"and" operation with the value of u, storingthe result into u.

The full process is performed atomically.

func (*Uint32)CompareAndSwap

func (u *Uint32) CompareAndSwap(old, newuint32)bool

CompareAndSwap atomically compares u's value with old,and if they're equal, swaps u's value with new.It reports whether the swap ran.

func (*Uint32)CompareAndSwapRelease

func (u *Uint32) CompareAndSwapRelease(old, newuint32)bool

CompareAndSwapRelease is a partially unsynchronized versionof Cas that relaxes ordering constraints. Other threadsmay observe operations that occur after this operation toprecede it, but no operation that precedes iton this thread can be observed to occur after it.It reports whether the swap ran.

WARNING: Use sparingly and with great care.

func (*Uint32)Load

func (u *Uint32) Load()uint32

Load accesses and returns the value atomically.

func (*Uint32)LoadAcquire

func (u *Uint32) LoadAcquire()uint32

LoadAcquire is a partially unsynchronized versionof Load that relaxes ordering constraints. Other threadsmay observe operations that precede this operation tooccur after it, but no operation that occurs after iton this thread can be observed to occur before it.

WARNING: Use sparingly and with great care.

func (*Uint32)Or

func (u *Uint32) Or(valueuint32)

Or takes value and performs a bit-wise"or" operation with the value of u, storingthe result into u.

The full process is performed atomically.

func (*Uint32)Store

func (u *Uint32) Store(valueuint32)

Store updates the value atomically.

func (*Uint32)StoreRelease

func (u *Uint32) StoreRelease(valueuint32)

StoreRelease is a partially unsynchronized versionof Store that relaxes ordering constraints. Other threadsmay observe operations that occur after this operation toprecede it, but no operation that precedes iton this thread can be observed to occur after it.

WARNING: Use sparingly and with great care.

func (*Uint32)Swap

func (u *Uint32) Swap(valueuint32)uint32

Swap replaces u's value with new, returningu's value before the replacement.

typeUint64

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

Uint64 is an atomically accessed uint64 value.

8-byte aligned on all platforms, unlike a regular uint64.

A Uint64 must not be copied.

func (*Uint64)Add

func (u *Uint64) Add(deltaint64)uint64

Add adds delta to u atomically, returningthe new updated value.

This operation wraps around in the usualtwo's-complement way.

func (*Uint64)CompareAndSwap

func (u *Uint64) CompareAndSwap(old, newuint64)bool

CompareAndSwap atomically compares u's value with old,and if they're equal, swaps u's value with new.It reports whether the swap ran.

func (*Uint64)Load

func (u *Uint64) Load()uint64

Load accesses and returns the value atomically.

func (*Uint64)LoadAcquire

func (u *Uint64) LoadAcquire()uint64

LoadAcquire is a partially unsynchronized versionof Load that relaxes ordering constraints. Other threadsmay observe operations that precede this operation tooccur after it, but no operation that occurs after iton this thread can be observed to occur before it.

WARNING: Use sparingly and with great care.

func (*Uint64)Store

func (u *Uint64) Store(valueuint64)

Store updates the value atomically.

func (*Uint64)StoreRelease

func (u *Uint64) StoreRelease(valueuint64)

StoreRelease is a partially unsynchronized versionof Store that relaxes ordering constraints. Other threadsmay observe operations that occur after this operation toprecede it, but no operation that precedes iton this thread can be observed to occur after it.

WARNING: Use sparingly and with great care.

func (*Uint64)Swap

func (u *Uint64) Swap(valueuint64)uint64

Swap replaces u's value with new, returningu's value before the replacement.

typeUint8

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

Uint8 is an atomically accessed uint8 value.

A Uint8 must not be copied.

func (*Uint8)And

func (u *Uint8) And(valueuint8)

And takes value and performs a bit-wise"and" operation with the value of u, storingthe result into u.

The full process is performed atomically.

func (*Uint8)Load

func (u *Uint8) Load()uint8

Load accesses and returns the value atomically.

func (*Uint8)Or

func (u *Uint8) Or(valueuint8)

Or takes value and performs a bit-wise"or" operation with the value of u, storingthe result into u.

The full process is performed atomically.

func (*Uint8)Store

func (u *Uint8) Store(valueuint8)

Store updates the value atomically.

typeUintptr

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

Uintptr is an atomically accessed uintptr value.

A Uintptr must not be copied.

func (*Uintptr)Add

func (u *Uintptr) Add(deltauintptr)uintptr

Add adds delta to u atomically, returningthe new updated value.

This operation wraps around in the usualtwo's-complement way.

func (*Uintptr)CompareAndSwap

func (u *Uintptr) CompareAndSwap(old, newuintptr)bool

CompareAndSwap atomically compares u's value with old,and if they're equal, swaps u's value with new.It reports whether the swap ran.

func (*Uintptr)Load

func (u *Uintptr) Load()uintptr

Load accesses and returns the value atomically.

func (*Uintptr)LoadAcquire

func (u *Uintptr) LoadAcquire()uintptr

LoadAcquire is a partially unsynchronized versionof Load that relaxes ordering constraints. Other threadsmay observe operations that precede this operation tooccur after it, but no operation that occurs after iton this thread can be observed to occur before it.

WARNING: Use sparingly and with great care.

func (*Uintptr)Store

func (u *Uintptr) Store(valueuintptr)

Store updates the value atomically.

func (*Uintptr)StoreRelease

func (u *Uintptr) StoreRelease(valueuintptr)

StoreRelease is a partially unsynchronized versionof Store that relaxes ordering constraints. Other threadsmay observe operations that occur after this operation toprecede it, but no operation that precedes iton this thread can be observed to occur after it.

WARNING: Use sparingly and with great care.

func (*Uintptr)Swap

func (u *Uintptr) Swap(valueuintptr)uintptr

Swap replaces u's value with new, returningu's value before the replacement.

typeUnsafePointer

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

UnsafePointer is an atomically accessed unsafe.Pointer value.

Note that because of the atomicity guarantees, stores to valuesof this type never trigger a write barrier, and the relevantmethods are suffixed with "NoWB" to indicate that explicitly.As a result, this type should be used carefully, and sparingly,mostly with values that do not live in the Go heap anyway.

An UnsafePointer must not be copied.

func (*UnsafePointer)CompareAndSwap

func (u *UnsafePointer) CompareAndSwap(old, newunsafe.Pointer)bool

CompareAndSwap atomically compares u's value with old,and if they're equal, swaps u's value with new.It reports whether the swap ran.

func (*UnsafePointer)CompareAndSwapNoWB

func (u *UnsafePointer) CompareAndSwapNoWB(old, newunsafe.Pointer)bool

CompareAndSwapNoWB atomically (with respect to other methods)compares u's value with old, and if they're equal,swaps u's value with new.It reports whether the swap ran.

WARNING: As the name implies this operation does *not*perform a write barrier on value, and so this operation mayhide pointers from the GC. Use with care and sparingly.It is safe to use with values not found in the Go heap.Prefer CompareAndSwap instead.

func (*UnsafePointer)Load

func (u *UnsafePointer) Load()unsafe.Pointer

Load accesses and returns the value atomically.

func (*UnsafePointer)Store

func (u *UnsafePointer) Store(valueunsafe.Pointer)

Store updates the value atomically.

func (*UnsafePointer)StoreNoWB

func (u *UnsafePointer) StoreNoWB(valueunsafe.Pointer)

StoreNoWB updates the value atomically.

WARNING: As the name implies this operation does *not*perform a write barrier on value, and so this operation mayhide pointers from the GC. Use with care and sparingly.It is safe to use with values not found in the Go heap.Prefer Store instead.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp