0% found this document useful (0 votes)
526 views

Reader Writer Problem Using Semaphore

The document describes implementing the reader-writer problem using semaphores. It declares three semaphore variables and a shared variable to be accessed by reader and writer processes. Reader processes first check if a writer is active and wait if so, then read the shared variable and signal. Writer processes check if any other processes are accessing the shared variable, write to it if not, and then signal. Pthreads allows simultaneous execution of reader and writer processes.

Uploaded by

bharathimanian
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
526 views

Reader Writer Problem Using Semaphore

The document describes implementing the reader-writer problem using semaphores. It declares three semaphore variables and a shared variable to be accessed by reader and writer processes. Reader processes first check if a writer is active and wait if so, then read the shared variable and signal. Writer processes check if any other processes are accessing the shared variable, write to it if not, and then signal. Pthreads allows simultaneous execution of reader and writer processes.

Uploaded by

bharathimanian
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

READER WRITER PROBLEM USING SEMAPHORE

Ex. No. : Date :

AIM: To implement 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.

You might also like