Homework 5 K BABANAZAR 2019529628030 Version 0 |
|
👤 Author: by wx287_oz26ft-3_gi3ergmjooq4q7gvhl0 2022-02-17 13:04:32 |
Solution:
Assuming that a database could be shared by multi-threads. Some threads are used for only reading while others are functioning upgrading. The former user is called the reader and the latter is called the write. If writing and other users (neither writer nor reader) concurrently share the object it might be confusing. At this time, to ensure such kinds of hard cases happen, writers are required to exclude the others who access the shared databases,
typedef strut {int value; struct process list;}s
typedef
struct int value;
struct process list; } semaphore;
semaphore mutex, wrt;
int readcount;
do {
wait(wrt);
//writing is performed
signal(wrt);
while(TRUE);
For reader:
do{
wait(mutex);
readcount++;
if (readcount==1);
wait(wrt);
signal(mutex);
//reading is performed
wait(mutex);
readcount++;
if(readcount==0)
signal(wrt);
signal(mutex);
}
Please login to reply. Login