Inspectopedia Help

Incorrect usage of the 'sync/atomic' package

Reports assignment statements of the form x = atomic.AddUint64(&x, 1).

Such operations are not atomic, and is a common misuse of the sync/atomic API. To make them atomic, one need to remove the assignment to use a direct call: atomic.AddUint64(&x, 1). In that case, the value of x will be updated atomically by address.

Example:

import ( "sync/atomic" ) type Counter uint64 func AtomicTests() { x := uint64(1) x = atomic.AddUint64(&x, 1) // ERROR "direct assignment to atomic value" _, x = 10, atomic.AddUint64(&x, 1) // ERROR "direct assignment to atomic value" x, _ = atomic.AddUint64(&x, 1), 10 // ERROR "direct assignment to atomic value" }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

GoVetAtomic
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Go | Probable bugs

Availability

By default bundled with

GoLand 2024.1, Qodana for Go 2024.1,

Can be installed with plugin

Go, 241.SNAPSHOT

Last modified: 18 June 2024