-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Open
Labels
FeatureRequestIssues asking for a new feature that does not need a proposal.Issues asking for a new feature that does not need a proposal.RefactoringIssues related to refactoring toolsIssues related to refactoring toolsToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.Issues related to the Go language server, gopls.
Milestone
Description
Go 1.19 introduced new atomic types (wrappers). Allowing one to replace:
var x int32
for range 100 {
go atomic.AddInt32(&x, 1)
}With:
var x atomic.Int32
for range 100 {
go x.Add(1)
}On the whole, this is safer, as the atomic types don't allow non-atomic access, which is a source of bugs. Note the +checkatomic annotation of checklocks.
These new-style atomics also don't suffer from misalignment problems, see dominikh/go-tools#171.
Not all usages are (easily) migratable, a non-exhaustive list of the top of my head:
- Initialized values (e.g.:
x := int32(42)), though this could be done with an ugly closure, it may not be worth it. - Multi-package usages (exposed atomics, if they exist for some reason)
- ...(probably a lot more)
cc @adonovan
Metadata
Metadata
Assignees
Labels
FeatureRequestIssues asking for a new feature that does not need a proposal.Issues asking for a new feature that does not need a proposal.RefactoringIssues related to refactoring toolsIssues related to refactoring toolsToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.Issues related to the Go language server, gopls.