If not, the above code is unsafe because a use of f.c (elsewhere)
could be halfway through loading f.c when
f.c = global_closed
is run, causing corruption, and the race detector is correct.
--
Alex Bligh
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
On 26 Apr 2016, at 19:20, Sokolov Yura <funny....@gmail.com> wrote:
> You understand wrong.
>
> Channel is used only to signal waters, that value is already set.
> Channel itself does not contain any value. It is just "broadcaster".
> That is why closed channel (in my use case) is not distinguishable
> from other closed channel.
I understand that perfectly, and as I said, in that case I don't
see what material space you are saving.
go today on the compiler you are using today might compile
f.c = global_closed as something which
on some architectures is atomic, but it provides no guarantee
of it. Tomorrow it might not. It might choose to store byte by
byte. Or store an intermediate value and then the real value.
You have no guarantee, and that's what the race detector is
correctly flagging up.
> But code is ugly and not faster than wrapping with mutex :-(
> I suppose, code is slower cause it is ugly, and Go's optimizer does no job well.
By far the least ugly route would be to not use global_closed.
--
Alex Bligh
go today on the compiler you are using today might compile
f.c = global_closed as something which
on some architectures is atomic, but it provides no guarantee
of it. Tomorrow it might not. It might choose to store byte by
byte. Or store an intermediate value and then the real value.
You have no guarantee, and that's what the race detector is
correctly flagging up.
--
Alex Bligh
Thomas, you are almost right.But it should be "general library" code, so it shall behave well in every situation, without presumptions.
That is untill you have millions of few dozens bytes.
26 апр. 2016 г. 11:54 PM пользователь "Dan Kortschak" <dan.ko...@adelaide.edu.au> написал:
>
> Two ways:
>
> http://play.golang.org/p/0YMzijuizE
>
>
> The merits of doing either of these things for any particular purpose are not commented on here.
Cast to unsafe.Pointer is obvious.
Harder to cast pointer back to `chan` and `map`.
I've already found a way to cast it back.
But code is ugly, and there other simpler workarounds exist.
Main intention were to have ability to use `select` statement.
Unfortunately, there is no ability to select from WaitGroup.