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

sync/atomic: explain how to add -1 using AddUint32 #6408

Closed
gopherbot opened this issue Sep 17, 2013 · 7 comments
Closed

sync/atomic: explain how to add -1 using AddUint32 #6408

gopherbot opened this issue Sep 17, 2013 · 7 comments

Comments

@gopherbot
Copy link

by runner.mei:

Add atomic Sub* operation to sync/atomic package.

func SubUint32(addr *uint32, new uint32) (old uint32)
func SubUint64(addr *uint64, new uint64) (old uint64)

Add and Sub is useful for stats counters
@minux
Copy link
Member

minux commented Sep 17, 2013

Comment 1:

Sub(x) could be emulated by Add(1<<width-x), so why introducing more APIs?

@gopherbot
Copy link
Author

Comment 2 by runner.mei:

It's not very friendly for most programmers (like me),this is too hard

@robpike
Copy link
Contributor

robpike commented Sep 17, 2013

Comment 3:

Also AddInt32(-int32(x))

@davecheney
Copy link
Contributor

Comment 4:

I will add some examples to the package to show how Sub can be implemented.

Labels changed: added priority-later, go1.2maybe, documentation, removed priority-triage.

Owner changed to @davecheney.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Sep 17, 2013

Comment 5:

SubUint32(addr, x) is AddUint32(addr, -x). This part isn't even worth a comment.
The only time this is awkward is when x is a constant and you're using an unsigned type.
I think that's a more general issue with constants, although not one I have a solution
to.
The easiest fix is to use a signed count.

@robpike
Copy link
Contributor

robpike commented Oct 3, 2013

Comment 7:

This issue was closed by revision c457963.

Status changed to Fixed.

@bradfitz
Copy link
Contributor

bradfitz commented Nov 3, 2013

Comment 8:

Issue #6711 has been merged into this issue.

@rsc rsc added this to the Go1.2 milestone Apr 14, 2015
@rsc rsc removed the go1.2maybe label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
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

6 participants