atomic

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicDo

func AtomicDo[T any](actor *Actor, owner *T, f func(*T))

AtomicDo executes f with actor-style serialization.

func AtomicDoN added in v0.3.0

func AtomicDoN(actors []*Actor, f func())

AtomicDoN runs f with the locks of ALL given actors held together, acquired in a canonical (pointer-address) order and released in reverse. This is the deadlock-free way to operate on several instances atomically — use it instead of nesting AtomicDo on different instances (which does NOT lock the inner one).

It is a general-purpose primitive: any struct that holds an *Actor (via NewActor) gets per-instance serialization (AtomicDo) AND deadlock-free multi-instance locking (AtomicDoN). Actors may belong to different groups; nil or already-held actors are skipped and duplicate pointers de-duplicated.

// Lock two custom structs together, deadlock-free:
atomic.AtomicDoN([]*atomic.Actor{a.actor, b.actor}, func() {
	b.data = append(b.data, a.data...)
})

func AtomicDoNWithInit added in v0.3.0

func AtomicDoNWithInit(actors []*Actor, initHooks []func(), f func())

AtomicDoNWithInit is AtomicDoN plus a per-actor one-time init hook (initHooks[i] pairs with actors[i]); nil entries and short slices are fine.

func AtomicDoWithInit

func AtomicDoWithInit[T any](actor *Actor, owner *T, f func(*T), initHook func())

AtomicDoWithInit executes f with actor-style serialization and runs initHook once.

Types

type Actor

type Actor = core.AtomicActor

Actor provides actor-style serialized execution for any struct.

func NewActor

func NewActor(group *Group) *Actor

NewActor creates a new Actor bound to the provided group. If group is nil, DefaultGroup is used.

type Group

type Group = core.AtomicGroup

Group defines a reentrancy scope for AtomicDo.

func DefaultGroup

func DefaultGroup() *Group

DefaultGroup returns the package-wide default group.

func NewGroup

func NewGroup() *Group

NewGroup creates a new Group.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL