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

x/sync/semaphore: newWeighted why n is int64 #27363

Closed
Sherlock-Holo opened this issue Aug 30, 2018 · 3 comments
Closed

x/sync/semaphore: newWeighted why n is int64 #27363

Sherlock-Holo opened this issue Aug 30, 2018 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@Sherlock-Holo
Copy link

Please answer these questions before submitting your issue. Thanks!
https://github.com/golang/sync/blob/master/semaphore/semaphore.go#L25

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

1.10.4

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sherlock/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/sherlock/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
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-build083961696=/tmp/go-build -gno-record-gcc-switches"

What did you do?

use semaphore.NewWeighted

What did you expect to see?

n should be uint64, because uint64 is large enough

What did you see instead?

n is int64

@gopherbot gopherbot added this to the Unreleased milestone Aug 30, 2018
@FiloSottile FiloSottile added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 30, 2018
@FiloSottile
Copy link
Contributor

I imagine the advantages of switching to uint64 are not worth breaking the API compatibility, but @jba might have more info on why.

@Sherlock-Holo
Copy link
Author

I discussed it with my friends, we suppose we almost won't use a number larger than maxint64. however uint64 can smaller than 0 and wet won't make n smaller than 0 so it won't panic

@ianlancetaylor
Copy link
Contributor

In general numbers should be signed unless it is important that they be unsigned. All computer integers have strange behavior at some points. Signed integers have strange behavior at very large absolute values. Unsigned integers have strange behavior at zero. Zero is much more common in real life, so on average we minimize surprises by using signed integers.

@golang golang locked and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants