== Go 1.19 added an _atomic.Pointer_ type that's a generic type In Go 1.18, the Go developers were careful to keep generic types out of the standard library, to the point where [[they decided not to have a '_constraints_' package of generics helpers in the standard library Go118NoConstraintsPackage]], never mind generic versions of slices and maps. As [[the Go 1.18 release notes say https://go.dev/doc/go1.18#generics]], all three packages were instead put under [[golang.org/x/exp https://pkg.go.dev/golang.org/x/exp/]]. However, Go 1.19 turns out to have somewhat quietly changed that, adding the standard library's first public generic type in [[sync/atomic https://pkg.go.dev/sync/atomic]]'s new [[_atomic.Pointer[T any]_ https://pkg.go.dev/sync/atomic#Pointer]] type. The atomic.Pointer type is a type-safe atomic pointer to a ``*T'', with the type safety assured at compile time. You could previously do atomic pointers through [[_atomic.Value_ https://pkg.go.dev/sync/atomic#Value]], but that was only type safe at runtime and might panic if you violated type safety (and storing a nil in one was complex (but possible)). The appeal of atomic.Pointer as a generic type is pretty obvious and it also seems unlikely that you could design a better generic type or a better API than the one it uses (which atomic.Value had from Go 1.4 and Go 1.17 (for _.CompareAndSwap()_)). I suspect that all of this adds up to why it was considered safe to add to the standard library in Go 1.19, and thus commit Go to having it there as part of the compatibility guarantee. The background and discussion for this is in [[issue $47141, Updating the Go memory model https://github.com/golang/go/discussions/47141]] and [[issue 50860, sync/atomic: add typed atomic values https://github.com/golang/go/issues/50860]]. Also, [[the commit message https://go.googlesource.com/go/+/ffe48e00adf3078944015186819a1ed5c6aa8bec]] has some interesting additional details. Apparently using these new atomic types, including atomic.Pointer[T], will generally compile down to the relevant assembly level atomic instructions. I'm not sure why I overlooked that this was added in Go 1.19 until now; I would have thought I'd pay more attention to the first generic type in the standard library. The [[Go 1.19 release notes https://go.dev/doc/go1.19]] mention it vaguely in [[New atomic types https://go.dev/doc/go1.19#atomic_types]] but don't specifically call out that it's a generic type; however, [[the Go 1.19 release announcement https://go.dev/blog/go1.19]] does specially talk about _atomic.Pointer[T]_, making it pretty clear that this is a generic type. === Sidebar: Storing a nil in an atomic.Value As the documentation says, atomic.Value will panic if you call _.Store(nil)_. However, Store takes an '_interface{}_' (now called '_any_'), which means that you can pass it a concretely typed nil and it will accept it: .pn prewrap on > var i int > var p *int > var m atomic.Value > > m.Store(&i) > // Both of these are accepted > m.Store(p) > m.Store((*int)(nil)) If you look at it from the right direction, this is part of how [[nil is typed in theory but not always in practice GoNilIsTypedSortOf]]. One way to put it is that if _atomic.Value_ is handed a pure nil, the nil is functionally untyped, which means that atomic.Value can't verify that it's the 'right' type of value (or use it to establish the type).