Skip to content

spinning-empty-loop

Detect empty loops that consume a core while waiting unsafely.

Updated View as Markdown

Default severity: warning

An empty unconditional loop spins at full speed. An empty loop that only rereads variables can terminate only through unsynchronized mutation, which is a data race. Use synchronization or a blocking operation instead.

Conditions containing calls or channel receives are accepted because their result can change dynamically. Constant-false loops are accepted as disabled debug scaffolding.

Bad

for {}

Good

for !ready() {} // condition is dynamically evaluated
Navigation

Type to search…

↑↓ navigate↵ selectEsc close