Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Operating Systems Questions: In the readers/writers problem, explain what semaphores mutex and db do, and how they work in reader's and writer's processess, respectively HERE
Operating Systems Questions:
In the readers/writers problem, explain what semaphores mutex and db do, and how they work in reader's and writer's processess, respectively
HERE
typedef int semaphore; semaphore mutex1; semaphore db 1 int rc 0; /* use your imagination/ /* controls access to rc /controls access to the database/ /* # of processes reading or wanting to */ void reader(void) /* repeat forever/ /*get exclusive access to rc/ /one reader more now /* if this is the first reader ...*/ /release exclusive access to rc / access the data/ /* get exclusive access to rc*/ /*one reader fewer now /if this is the last reader / release exclusive access to rc/ * noncritical region / while (TRUE) down(&mutex); if (rc1) down(&db);/* this up(&mutex) read_data_base(); down(&mutex); rc rc 1 if (rc0 up(&db); up(&mutex) use_data read(); void writer(void) * repeat forever/ /* noncritical region /* get exclusive access/ *update the data*/ / release exclusive access while (TRUE) think up_data(); down(&db); write_data base(); up(&db) Figure 2-48. A solution to the readers and writers problem typedef int semaphore; semaphore mutex1; semaphore db 1 int rc 0; /* use your imagination/ /* controls access to rc /controls access to the database/ /* # of processes reading or wanting to */ void reader(void) /* repeat forever/ /*get exclusive access to rc/ /one reader more now /* if this is the first reader ...*/ /release exclusive access to rc / access the data/ /* get exclusive access to rc*/ /*one reader fewer now /if this is the last reader / release exclusive access to rc/ * noncritical region / while (TRUE) down(&mutex); if (rc1) down(&db);/* this up(&mutex) read_data_base(); down(&mutex); rc rc 1 if (rc0 up(&db); up(&mutex) use_data read(); void writer(void) * repeat forever/ /* noncritical region /* get exclusive access/ *update the data*/ / release exclusive access while (TRUE) think up_data(); down(&db); write_data base(); up(&db) Figure 2-48. A solution to the readers and writers
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started