Repository navigation
Introduction
Package spin provides minimal spin primitives for performance-critical Go code paths: Lock for ultra-short critical sections, Wait for adaptive polling, Pause for architecture-specific CPU pause hints, and Yield for cooperative yielding outside hot paths. It is designed for code where allocation, scheduler overhead, and avoidable cache-line traffic matter. Lock remains intentionally non-fair and specialized; general-purpose mutual exclusion should still use sync.Mutex. Wait gives callers a compact adaptive backoff surface, moving from pause hints toward scheduler cooperation as a polling loop ages. Pause exposes the lowest-level CPU hint operation while preserving a compact, allocation-free hot-path surface. Yield stays the explicit escape hatch for non-hot paths that should give other goroutines time to run.
Usage
var sw spin.Wait
for !ready {
sw.Once()
}
spin.Pause() // 30 pause hints by default
spin.Pause(50) // 50 pause hintsHighlights
This patch clarifies the public wording around Pause(cycles): cycles is a repeat count for pause hints, not a calibrated CPU-cycle delay. The documentation now states the hardware and fallback behavior explicitly, so callers can distinguish hardware-pause targets from wasm and unsupported fallback targets.
What's Changed
Documentation
- Clarify
Pause(cycles)GoDoc and multilingual README wording: the default is 30 pause hints,cyclesis a repeat count, and fallback targets may yield throughruntime.Gosched()(#10)
Chore
- Update CI action versions and add explicit test timeouts while keeping the Go 1.26.x workflow and coverage gate intact (#10)
Compatibility
- Go: 1.26+
- Platforms: linux/amd64, linux/arm64, linux/386, linux/arm, linux/riscv64, linux/loong64, linux/ppc64le, linux/s390x, wasm