|Unreliable Guide To Locking|
|Prev||Chapter 2. Two Main Types of Kernel Locks: Spinlocks and Semaphores||Next|
Both spinlocks and semaphores have read/write variants: rwlock_t and struct rw_semaphore. These divide users into two classes: the readers and the writers. If you are only reading the data, you can get a read lock, but to write to the data you need the write lock. Many people can hold a read lock, but a writer must be sole holder.
This means much smoother locking if your code divides up neatly along reader/writer lines. All the discussions below also apply to read/write variants.