LoadInt32 atomically reads a signed 32-bit integer through Go's sync/atomic package. It provides a safe read of a shared atomic value after concurrent goroutines finish. section 12.1.1 section 12.1.3
Reading a shared balance
After Stingy and Spendy update the shared int32 with atomic additions, a WaitGroup waits for both goroutines, then atomic.LoadInt32(&money) reads the final balance. The program reports $100 without race conditions. section 12.1.1
Use LoadInt32 when reading results produced by atomic updates:
- Store shared counters as int32 values because these atomic operations apply to specific integer types. section 12.1.3
- Load each completed counter with atomic.LoadInt32, even when goroutines have already finished, to follow atomic-read practice. section 12.1.3
func AddInt32(addr *int32, delta int32) (new int32) func CompareAndSwapInt32(addr *int32, old, new int32) (swapped bool) func LoadInt32(addr *int32) (val int32) func StoreInt32(addr *int32, val int32) func SwapInt32(addr *int32, new int32) (old int32)
View LoadInt32 alongside Go's related atomic operations and function signatures. section 12.1.1
