Reputation: 403
go1.19 introduce atomic.Pointer, and I noticed Some source code has moved from atomic.Value to atomic.Pointer. (ex: 426074: sync: switch Map to use atomic.Pointer, 422174: encoding/gob: change typeInfo.encoder type to atomic.Pointer[T])
So my question are:
Upvotes: 2
Views: 2140
Reputation: 44
Prefer more specific atomic types over atomic.Value
. Just as atomic.Bool
is preferred over atomic.Value
when working with bool
values, atomic.Pointer
is preferred over atomic.Value
when working with pointers.
If my code considers using generics, can all atomic.Value's be converted to atomic.Pointer's and what are the cases where atomic.Value's should be used more?
Convert from atomic.Value
to atomic.Pointer
when the value is a pointer.
Is the existence of atomic.Value only for compatibility reasons, should atomic.Value be gradually deprecated?
The atomic types that are more specific than atomic.Value
do not cover all possible types. There's still a need atomic.Value
.
Upvotes: 2