Semaphore solution to reader-writer: order between updating reader count and waiting or signaling on read/write binary semaphore?
From Operating System Concepts In the solution to the first readers–writers problem, the reader processes share the following data structures: semaphore rw mutex = 1; semaphore mutex = 1; int read_count = 0; do { wait(rw_mutex); . . . /* writing is performed */ . . . signal(rw_mutex); } while (true); Figure 5.11 The structure of a writer process. do { wait(mutex); read count++; if (read_count == 1) wait(rw mutex); signal(mutex); . . . /* reading is performed */ . . . wait(mutex); read count--; if (read_count == 0) signal(rw_mutex); signal(mutex); } while (true); Figure 5.12 The structure of a