LLMpediaThe first transparent, open encyclopedia generated by LLMs

Spinlock

Generated by GPT-5-mini
Note: This article was automatically generated by a large language model (LLM) from purely parametric knowledge (no retrieval). It may contain inaccuracies or hallucinations. This encyclopedia is part of a research project currently under review.
Article Genealogy
Expansion Funnel Raw 73 → Dedup 0 → NER 0 → Enqueued 0
1. Extracted73
2. After dedup0 (None)
3. After NER0 ()
4. Enqueued0 ()
Spinlock
NameSpinlock
TypeSynchronization primitive
FieldComputer science

Spinlock.

A spinlock is a low-level synchronization primitive used in concurrent programming and operating system kernels to protect shared resources by busy-waiting. It appears in designs and implementations across Unix, Linux kernel, FreeBSD, Windows NT, and BSD-derived systems, and is discussed in works by authors associated with Dennis Ritchie, Ken Thompson, Andrew S. Tanenbaum, and Linus Torvalds.

Overview

A spinlock uses repeated test-and-set or compare-and-swap operations provided by architectures such as x86, ARM architecture, PowerPC, SPARC, and RISC-V to implement mutual exclusion in contexts like interrupt handlers, device drivers, and short critical sections in kernels such as Linux kernel and XNU. Implementations rely on atomic primitives from vendors like Intel Corporation, ARM Ltd., IBM and are described in textbooks by Andrew S. Tanenbaum and Herbert S. Wilf. Spinlocks are contrasted with blocking primitives in systems like POSIX threads, Windows NT synchronization APIs, and language runtimes such as Java Virtual Machine and .NET Framework.

Implementation and Variants

Common implementations use atomic instructions—Test-and-Set, Compare-and-Swap, or Load-Link/Store-Conditional—available on architectures including x86, ARM architecture, MIPS, PowerPC, and RISC-V. Variants include ticket locks influenced by work from researchers associated with M.L. Scott and John Mellor-Crummey, MCS locks (Mellor‑Crummey and Scott) used in Linux kernel and research repositories, queued locks used in Solaris and NetBSD, and adaptive spinlocks in FreeBSD and Linux kernel that mix spinning and blocking with schedulers like those from Microsoft Research and Bell Labs. Implementation details appear in source trees of Linux kernel, FreeBSD, OpenBSD, and academic papers presented at conferences such as USENIX, ACM SIGPLAN, and ACM SIGOPS.

Performance and Scalability

Performance depends on CPU topology (NUMA effects on Non-Uniform Memory Access systems), cache coherence protocols by vendors like Intel Corporation and AMD, and scheduler interactions in Linux kernel and Windows NT. Spinlocks perform well for short critical sections on single-socket systems and in low-latency contexts in embedded systems and real-time operating systems, but scalability can degrade under high contention on multi-core servers such as those from Dell, HP, and IBM. Studies comparing ticket locks, MCS locks, and simple test-and-set appear in papers from ACM and IEEE conferences and in performance suites like those used at SPEC and by organizations such as Red Hat.

Use Cases and Applications

Spinlocks are used in kernel subsystems in Linux kernel for interrupt-safe locking, in hypervisor codebases such as Xen Project and KVM, in firmware and bootloaders from Intel Corporation and ARM Ltd., in device drivers for vendors like NVIDIA, Broadcom, and Intel Corporation, and in embedded RTOSes like FreeRTOS and ThreadX. Users appear in high-frequency trading systems on platforms by Goldman Sachs and Morgan Stanley, in network stacks for Cisco Systems and Juniper Networks, and in game engine subcomponents by studios such as Ubisoft and Electronic Arts where low-latency locking is critical.

Correctness and Fairness

Correctness relies on atomic instruction semantics from Intel Corporation and ARM Ltd. and on memory model definitions formalized by researchers at Microsoft Research, IBM Research, and universities such as MIT and Stanford University. Fairness properties vary: simple test-and-set locks can starve threads on architectures with weak fairness, whereas ticket locks and MCS locks provide bounded turnaround demonstrated in research at ACM SIGOPS and USENIX workshops. Formal verification efforts have been conducted in projects associated with seL4 and academic groups at University of Cambridge and Carnegie Mellon University.

Alternatives and Comparisons

Alternatives include blocking mutexes found in POSIX threads and Windows NT APIs, reader–writer locks used in databases like PostgreSQL and MySQL, transactional memory explored at Intel Research and IBM Research, futexes used in Linux kernel, and lock-free algorithms from work by Maurice Herlihy and M. Michael. Comparative studies appear in literature from ACM SIGPLAN, IEEE Real-Time Systems Symposium, and vendor white papers by Intel Corporation and ARM Ltd..

Category:Concurrency