ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > zstu-(2021-2022)-1 > 2019529628047 MOHAMMED ANVAR >
Homework 5 2019529628047 MOHAMMED ANVAR Version 0
👤 Author: by wx287_oz26ft8z0hrxg4bfxzjnbg_sik8g 2022-02-17 15:06:09
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

Reversion History

Loading...
No reversions found.