This document provides code for solving the reader-writer problem using mutexes and semaphores. It defines functions for reader and writer threads, initializes semaphores for mutex and writing, creates threads for the given number of readers and writers, and joins the threads. The reader and writer functions implement locking using semaphores - the reader function locks mutex before/after reading, and increments/decrements the read count, while the writer function waits on the write semaphore to enter the critical section.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
33 views
OS Assignment 2
This document provides code for solving the reader-writer problem using mutexes and semaphores. It defines functions for reader and writer threads, initializes semaphores for mutex and writing, creates threads for the given number of readers and writers, and joins the threads. The reader and writer functions implement locking using semaphores - the reader function locks mutex before/after reading, and increments/decrements the read count, while the writer function waits on the write semaphore to enter the critical section.