golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.31k stars 17.7k forks source link

proposal: add a handful of acquire/release atomics (make the internal runtime versions public) #70607

Open eloff opened 2 hours ago

eloff commented 2 hours ago

Proposal Details

I asked for this a decade ago, and I want to start this discussion up again.

I'm not saying Go should add the full gamut of relaxed, acquire, release, etc orderings available in other languages.

But I am saying it's useful to have some basic acquire and release loads and stores for 32bit, 64bit, and uintptr.

To see that this is useful one need look no further than the Go runtime which use exactly these.

uintptr: internal/runtime/atomic.LoadAcquintptr internal/runtime/atomic.StoreReluintptr

uint32: internal/runtime/atomic.LoadAcq internal/runtime/atomic.StoreRel

uint64: internal/runtime/atomic.LoadAcq64 internal/runtime/atomic.StoreRel64

I would like that we make these 6 functions available in the atomics package and a LoadAcq and StoreRel on each of the atomic types. I can make a PR.

It's not that these are so advanced and so dangerous that only Go runtime authors should have them. We deserve advanced tools too. For a language with concurrency as a strength, it's lacking in some important primitives to develop performant concurrent data structures. And it's not that we can't have that in Go, it's already implemented, it just isn't public.

gabyhelp commented 2 hours ago

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

randall77 commented 1 hour ago

As far as I can tell the current Rel and Acq versions only differ from the standard versions on ppc64. Is that your understanding as well?