Skip to content

spin v0.1.4 — Low-latency Spin Primitives for Go

Choose a tag to compare

@hayabusa-cloud hayabusa-cloud released this 05 Feb 05:11
· 6 commits to main since this release
8e19f81

Introduction

Package spin provides minimal spin primitives for low-latency code paths in Go. It offers a non-fair spinlock for ultra-short critical sections, an adaptive spin-wait helper for tight polling loops, architecture-specific CPU pause hints, and cooperative yield functions.

  • Supported architectures: amd64, arm64, riscv64, loong64, ppc64le, s390x, 386, wasm.

Usage

// Spinlock for ultra-short critical sections
var lk spin.Lock
lk.Lock()
// critical section
lk.Unlock()

// Adaptive spin-wait
var sw spin.Wait
for !condition {
    sw.Once()
}

// CPU pause hint
spin.Pause()

What's Changed

Improvements

  • Add comprehensive benchmarks
  • Add Makefile with test, bench, cover, vet, clean targets

Compatibility

  • Go: 1.25+
  • Platforms: linux/amd64, linux/arm64, linux/riscv64, linux/loong64, linux/ppc64le, linux/s390x, linux/386, js/wasm