-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: atomic keyword #14977
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
Comments
You can implement those operations using unsafe and the *Pointer varieties of sync/atomic.
So I'm not convinced this is worth a new keyword. The above code is tricky, but anyone (successfully) messing with atomics is an expert. |
@randall77 I have few counter points:
One more thing, It doesn't really have to be a keyword, it can be a type, for example |
I see several problems with this proposal:
Please note the first statement after the package synopsis "These functions require great care to be used correctly. Making atomics types easier to use is false sense of
What about "atomic [1024]byte" that is impossible to Also, we need to be careful what it means to pass atomic This is well understood: But, given these function declarations: which of the functions could you pass x to? Actually, this form of atomic reminds me of the const modifier |
This isn't going to be adopted. I'm going to close this issue. I don't know whether there is a problem here that needs to be addressed in Go. I am quite certain that adding an atomic type qualifier is not the answer. Experience with C++ shows that few people can program correctly with atomic types, and detecting errors is very difficult. This is not a road that Go should go down. And if it does go down them, it should not do so by using a type qualifier. |
Abstract
With the growing number of processor cores, many developers use atomics rather than mutex/cond when they can.
Background
For primitive types, we have
sync/atomic
, which provides Load/Store/Swap/CAS, however, for other types we only haveatomic.Value
, which only provides Load/Store and the added overhead of runtime type assertion since it usesinterface{}
Proposal
Here comes the atomic keyword (more like chan, but it can be something else really):
Implementation
It'd be implemented much like
atomic.Value
internally, probably using a spinlock for CAS and Swap operations, with the added runtime magic to handle types directly instead of using interface{}.Ideas? Feedback?
The text was updated successfully, but these errors were encountered: