Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to atomic.load/store a pointer #34840

Closed
zylthinking opened this issue Oct 11, 2019 · 1 comment
Closed

how to atomic.load/store a pointer #34840

zylthinking opened this issue Oct 11, 2019 · 1 comment

Comments

@zylthinking
Copy link

What version of Go are you using (go version)?

go version go1.13 linux/amd64

Does this issue reproduce with the latest release?

YES

What operating system and processor architecture are you using (go env)?

go env Output
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/zylthinking/.cache/go-build"
GOENV="/home/zylthinking/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY="*.qianxin-inc.cn"
GONOSUMDB="*.qianxin-inc.cn"
GOOS="linux"
GOPATH="/home/zylthinking/go"
GOPRIVATE="*.qianxin-inc.cn"
GOPROXY="https://goproxy.io"
GOROOT="/opt/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build825018572=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
    "fmt"
    "sync/atomic"
    "unsafe"
)

func main() {
    n := 0;
    n1 := 0;
    intp := &n;
    fmt.Println(&n, &n1);
    a := (unsafe.Pointer(&intp));
    fmt.Println(a, intp)
    atomic.StorePointer(&a, unsafe.Pointer(&n1));
    fmt.Println(a, intp)
}

What did you expect to see?

0xc00009e010 0xc00009e018
0xc0000a2018 0xc00009e010
0xc0000a2018 0xc00009e018

What did you see instead?

0xc0000a0000 0xc0000a0008
0xc000096018 0xc0000a0000
0xc0000a0008 0xc0000a0000

words

I do know how to generate the desired result, just

    a := (*unsafe.Pointer) (unsafe.Pointer(&intp));
    atomic.StorePointer(a, unsafe.Pointer(&n1));

however, &intp is Integer pointer, but it is not a *unsafe.Pointer
it is not like (*reflect.SliceHeader) and (*reflect.StringHeader) confirmed by std library to be compatible.

@agnivade
Copy link
Contributor

Hello @zylthinking, unlike other projects, we do not use the issue tracker for questions such as these. It is only used for bugs and feature proposals. I will close this issue, but please feel free to ask it in any of these forums below:

Thanks

@golang golang locked and limited conversation to collaborators Oct 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants