Re: [go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread 'Axel Wagner' via golang-nuts
I actually thought about it and your way is strictly better, as it supports CAS (if all interface types involved do), which the pointer-method doesn't. On Tue, Nov 16, 2021 at 5:16 PM Stephen Illingworth < stephen.illingwo...@gmail.com> wrote: > > How about just a 'container' type for the

Re: [go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread Stephen Illingworth
> How about just a 'container' type for the interface. >> >> https://play.golang.org/p/WSXVjVHj1Ya >> > >> For what I need, that does the job nicely. The type being stored in the >> atomic.Value isn't changing so it satisfies the atomic.Value constraints >> but I have the flexibility of the

Re: [go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread 'Axel Wagner' via golang-nuts
On Tue, Nov 16, 2021 at 3:33 PM Stephen Illingworth < stephen.illingwo...@gmail.com> wrote: > How about just a 'container' type for the interface. > > https://play.golang.org/p/WSXVjVHj1Ya > > For what I need, that does the job nicely. The type being stored in the > atomic.Value isn't changing

Re: [go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread Stephen Illingworth
> I've found that the way around this is to create a new instance of >> atomic.Value whenever I have reason to believe that the type to be stored >> has changed. >> > > That seems to be counter to the idea behind `atomic.Value`. Creating and > setting the new `atomic.Value` requires

Re: [go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread 'Axel Wagner' via golang-nuts
On Tue, Nov 16, 2021 at 1:25 PM Stephen Illingworth < stephen.illingwo...@gmail.com> wrote: > I've found that the way around this is to create a new instance of > atomic.Value whenever I have reason to believe that the type to be stored > has changed. > That seems to be counter to the idea

Re: [go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread Robert Engels
I believe your code is broken. You need to use a lock when checking and making the switch (see double locking problem) or there would be no need to use atomics. If you run it under the race detector I am guessing it will fail. > On Nov 16, 2021, at 6:25 AM, Stephen Illingworth > wrote: >

[go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread Stephen Illingworth
When using atomic.Values it is important that the type being stored is consistent. Trying to store a different type in an atomic.Value will cause a panic panic: sync/atomic: store of inconsistently typed value into Value I've found that the way around this is to create a new instance of