Help us shape the future of Go! Take the 2026 Go Developer Survey

atomicbool

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Atomic store and load of bool type.

Copyright 2017 Nicolas S. Dade

bool-in-uint32 atomic store and load.

This type exists because of the aliasing of up to 3 other byte sized variables in the 4 bytes containing a regular Go 'bool' trips up the go -race detection, producing false races, because from Go's point of view we were reading and writing the 4 bytes, even though we were only, and atomically, changing only one.

Copyright 2021 Nicolas S. Dade

Index

Constants

View Source
const (
	// True32 is the value of a Bool32 set to true. It's useful to initialize a Bool32 to true.
	True32 = Bool32(1)
)

Variables

This section is empty.

Functions

func LoadBool

func LoadBool(addr *bool) (val bool)

func StoreBool

func StoreBool(addr *bool, val bool)

Types

type Bool32 added in v1.1.0

type Bool32 uint32

Bool32 is a boolean stored in a uint32. It's sole purpose is to avoid go -race false positives which otherwise happen when a regular (1 byte) Go 'bool' is adjacent other variables in memory.

func (*Bool32) CompareAndSwap added in v1.1.0

func (b *Bool32) CompareAndSwap(old, new bool) (swapped bool)

CompareAndSwap atomically performs:

 if b == old {
   b = new
   return true
} else {

   return false
}

func (*Bool32) Load added in v1.1.0

func (b *Bool32) Load() bool

Load atomically loads and returns the boolean value of b

func (*Bool32) Store added in v1.1.0

func (b *Bool32) Store(x bool)

Store atomically stores x in b

Jump to

Keyboard shortcuts

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