Proposals Unofficial Go proposal tracker

Add atomic Max and Min operations

#63999 · sync/atomic · medium impact · Accepted ·

Programs sometimes need to atomically record the largest or smallest value seen so far, such as a peak counter or a high-water mark shared across goroutines. Today this requires a hand-written compare-and-swap loop. This proposal adds atomic Max and Min operations to sync/atomic. Some architectures, such as RISC-V with AMOMAX/AMOMIN, can implement them with a single instruction.

The new functions are MaxInt32, MaxInt64, MaxUint32, MaxUint64, MaxUintptr and the matching Min* functions. The Int32, Int64, Uint32, Uint64 and Uintptr types gain matching Max and Min methods. Each operation stores the larger or smaller of the current value and val, then returns the old value.

var peak atomic.Int64

func record(n int64) {
    peak.Max(n) // peak = max(peak, n), atomically
}

var lowest int32 = math.MaxInt32
old := atomic.MinInt32(&lowest, 42)
Proposal
#63999 by mauri870
Status
Accepted on Jul 15, 2026
Impact
medium
Area
sync/atomic