Using the reader-writer spinlock
Visualize a piece of kernel (or driver) code wherein a large, global data structure – say, a doubly linked circular list with a few thousand nodes or more – is being searched. Now, since this data structure is global (shared and writable), accessing it concurrently constitutes a critical section, and that requires protection.
Assuming a scenario where searching the list is a non-blocking operation, you’d typically use a spinlock to protect the critical section.
A naive approach might propose not using a lock at all, since we’re only reading data within the list, not updating it. But, of course, even a read on shared writable data has to be protected in order to protect against an inadvertent write occurring simultaneously (as you have learned – refer back to the previous chapter if required), thus resulting in a dirty or torn read.
So we conclude that we require the spinlock; we imagine the...