Because the kernel is threaded, and threads do what they do otherwise independently of one another, access to shared resources must be synchronised to prevent race conditions and inconsistent data.
The kernel provides a number of synchronisation mechanisms, depending on the usage scenario.
- Spinlock - This is an interrupt and SMP safe simple critical section locking mechanism, allowing only a single thread to own the spinlock at a time. A locked spinlock also disables interrupts on the locking processor, to prevent external interrupts from being handled, so spinlocks provide a safe means of sharing data between a device driver and a device interrupt handler.
- Interrupt monitor - This is an interrupt and SMP safe monitor built upon spinlocks. Threads can wait/signal monitors to coordinate access to the shared resource protected by the monitor, and provide the only means for a thread to sleep. Because monitors are spinlock based, interrupts are disabled while a monitor is held, allowing device drivers to coordinate with interrupt handlers.
- Monitor (non-interrupt safe) - This is an SMP safe monitor built upon interrupt monitors. Like interrupt monitors, threads can wait/signal monitors to coordinate access to the shared resource protected by the monitor.
- Reader/writer lock - This is an SMP safe reader/writer lock build upon monitors. Multiple readers, or a single writer, can lock the resource protected by the reader/writer lock, allowing safe, concurrent access to read-only resources, which can improve scalability if such a resource is seldom updated.