golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.95k stars 17.66k forks source link

x/tools/gopls: #53558

Closed dusx1981 closed 2 years ago

dusx1981 commented 2 years ago

gopls version

golang.org/x/tools/gopls v0.7.3 golang.org/x/tools/gopls@v0.7.3 h1:Lru57ht8vtDMouRskFC085VAjBAZRAISd/lwvwOOV0Q=

go env

GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/home/dusx/.cache/go-build" GOENV="/home/dusx/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/dusx/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/dusx/go" GOPRIVATE="" GOPROXY="https://goproxy.cn,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.17.6" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/dusx/htap/go.mod" 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-build1566950369=/tmp/go-build -gno-record-gcc-switches"

What did you do?

`` user sync.Pool to manage Objects

Through the test, we can know that if sync.Pool is written to the same object multiple times, like this: pool.Put(x) pool.Put(x), the buffer pool has no detection mechanism to ensure that the same object is not written multiple times. . Therefore, if the logic of using the cache is not rigorous, it will cause the same object to be written multiple times. If it is acquired multiple times, the same object will be used in different places, and the memory will be scrambled. So can you change the base class of the object to something like this: type BaseSyncPoolObject struct { cached bool } Check if cached is true when the object is put into the cache. If not true, put into cache and set to true. If true, do nothing. ``

ianlancetaylor commented 2 years ago

I'm sorry, that's not how the language works. There is no base class. And, if there were, we would not want to impose a cost on all values in order to let a few time avoid this problem in sync.Pool.

For questions or discussions, please see https://go.dev/wiki/Questions. Thanks.

dusx1981 commented 2 years ago

got it,thanks

---Original--- From: "Ian Lance @.> Date: Mon, Jun 27, 2022 12:57 PM To: @.>; Cc: @.**@.>; Subject: Re: [golang/go] x/tools/gopls: (Issue #53558)

I'm sorry, that's not how the language works. There is no base class. And, if there were, we would not want to impose a cost on all values in order to let a few time avoid this problem in sync.Pool.

For questions or discussions, please see https://go.dev/wiki/Questions. Thanks.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>