# missing-spin-loop

Require a processor hint in atomic busy-wait loops

An atomic polling loop that performs no other work repeatedly reloads the atomic value without informing the processor that it is spinning.
Instead, you SHOULD call `spinLoop` during bounded optimistic spinning or use a blocking synchronization operation for longer waits.

- Category: performance
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
import { Atomic } from "destack:sync";

function wait(ready: &readonly Atomic<boolean>): void {
    while (!ready.load()) {}
}
```

## Accepted

```ds title="main.ds"
import { spinLoop } from "destack:hint";
import { Atomic } from "destack:sync";

function wait(ready: &readonly Atomic<boolean>): void {
    while (!ready.load()) {
        spinLoop();
    }
}
```

## Prior art

- [Clippy · missing_spin_loop](https://rust-lang.github.io/rust-clippy/master/index.html#missing_spin_loop)

[language/linter/src/rules/performance/missing_spin_loop.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/performance/missing_spin_loop.rs#L8)
