The reader-writer mutex lock
Visualize a multithreaded application with some ten worker threads; let's say that, most of the time (say 90% of the time), eight of the workers are busy scanning a global linked list (or similar data structure). Now, of course, since it's global, we know that it's a critical section; failing to protect it with a mutex can easily result in a dirty read bug. But, this is at a major performance cost: as each worker thread wants to search the list, it is forced to wait upon the unlock event from the owner.
Computer scientists have come up with quite an innovate alternative for situations like this (also referred to as the reader-writer problem), wherein the data accesses are such that for the majority of time (shared) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access