Reader Writer Problem Using Semaphore
Reader Writer Problem Using Semaphore
ALGORITHM:
1. Start the program. 2. Declare three semaphore variable mutex and a shared variable which is used by reader and writer processes. 3. Wait and signal are two functions to implement the semaphore. Wait-waits until semaphore variable reach 1 and then decrements it. Signal increments the semaphore variable by 1. 4. The reader process, checks if any process is writing. If so it waits else it reads the content of shared variable and then signals. 5. The Writer process checks if any other process is accessing the shared variable. If not it changes the value of shared variable and then signals. 6. Pthreads is used to execute two processes simultaneously. 7. End he program.