Re: [go-nuts] How to safely convert a pointer to *unsafe.Pointer

2019-07-19 Thread Ian Lance Taylor
On Fri, Jul 19, 2019 at 4:33 PM  wrote:
>
> I would like to make sure that the following line of Go is a defined behavior:
>
>  addr := (*unsafe.Pointer)((unsafe.Pointer)())
>
> I use it to perform atomic loads and stores to addr such as in this simple 
> example: https://play.golang.org/p/DpDrRvTYMG8
> It allows me not to use atomic.Value which performs two atomic operations and 
> possible disable preemption 
> (https://golang.org/src/sync/atomic/value.go?s=1233:1269#L35).

Yes, that operation is defined.  As documented at
https://golang.org/pkg/unsafe, you can use unsafe.Pointer to convert
from a pointer to one type to a pointer to a different type.

Ian

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUq65RATwbr6z9RNthxqcJTEPwtVyiQXjU_04TpOKWKLw%40mail.gmail.com.


[go-nuts] How to safely convert a pointer to *unsafe.Pointer

2019-07-19 Thread julio
Hello,

I would like to make sure that the following line of Go is a defined 
behavior:

 addr := (*unsafe.Pointer)((unsafe.Pointer)())

I use it to perform atomic loads and stores to addr such as in this simple 
example: https://play.golang.org/p/DpDrRvTYMG8
It allows me not to use atomic.Value which performs two atomic operations 
and possible disable preemption (
https://golang.org/src/sync/atomic/value.go?s=1233:1269#L35).

Thanks for your help,
Julio

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3bc36e02-c821-4241-b929-c9c5abd5b4b7%40googlegroups.com.