Skip to content

Commit

Permalink
Fix util.AtomicMax comment
Browse files Browse the repository at this point in the history
  • Loading branch information
sharnoff committed Feb 6, 2023
1 parent 7eb9505 commit a35a561
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/util/arith.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ type AtomicInt[I any] interface {

// AtomicMax atomically sets a to the maximum of *a and i, returning the old value at a.
//
// Eventually, one would *hope* that go could add atomic maximum (and minimum), so we don't need
// this function (there are some ISAs that support such instructions). In the meantime though, this
// tends to be pretty useful - event though it's not wait-free.
// On ISAs without atomic maximum/minimum instructions, a fallback is typically implemented as the
// Load + CompareAndSwap loop that this function uses. At time of writing (Go 1.20), the Go standard
// library does not include atomic maximum/minimum functions.
//
// This function is lock-free but not wait-free.
func AtomicMax[A AtomicInt[I], I constraints.Integer](a A, i I) I {
for {
current := a.Load()
Expand Down

0 comments on commit a35a561

Please sign in to comment.