Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M6297

Spinlock

Spinlock
SystemsHigh supportSystems Theory
Included
account_tree

Version 1.0.0 · Updated 2026-07-28

CORE DEFINITION

A spinlock is a lock used in computer science for multi-threaded synchronization, where a thread repeatedly checks whether the lock variable is available. Since the thread remains executing during this process, it is a form of busy-waiting. Once a spinlock is acquired, the thread holds it until explicitly released. Spinlocks avoid the scheduling overhead of process context switching, making them effective in situations where threads block only for very short periods. Therefore, operating system implementations often use spinlocks in many places. The lightweight reader-writer lock (SRW Lock) provided by Windows internally uses spinlocks. Obviously, a single-core CPU is not suitable for spinlocks; here, single-core CPU refers to a single-core, single-threaded CPU, because at any given time only one thread is in the running state. Suppose running thread A finds that it cannot acquire the lock and can only wait for it to be unlocked, but because A does not suspend itself, the thread B holding the lock cannot enter the running state; it can only be scheduled after the time slice allocated to A by the operating system expires. In this case, using a spinlock is very costly. Acquiring and releasing a spinlock actually involves reading and writing the memory or register that stores the spinlock. Therefore, such read/write operations must be atomic.

SCAFFOLDING EFFECT

psychology

Reduce cognitive load

A spinlock is a lock used in computer science for multi-threaded synchronization, where a thread repeatedly checks whether the lock variable is available. Since the thread remains executing during this process, it is a form of busy-waiting. Once a spinlock is acquired, the thread holds it until explicitly released. Spinlocks avoid the scheduling overhead of process context switching, making them effective in situations where threads block only for very short periods. Therefore, operating system implementations often use spinlocks in many places. The lightweight reader-writer lock (SRW Lock) provided by Windows internally uses spinlocks.

anchor

Anchor fast decisions

When a thread cannot acquire the lock, it does not sleep but spins in a busy loop, avoiding context-switch overhead; suitable for very short critical sections and multi-core scenarios.

MINIMUM ACTION

In progress 0/4

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%
account_treeGenealogyexpand_more
menu_bookReferencesexpand_more

Source support: Explicit

  • link
    zh.wikipedia.orghttps://zh.wikipedia.org/wiki/%E8%87%AA%E6%97%8B%E9%94%81ZH · Explicit
    verified

RELATED MODELS