ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > zstu-(2021-2022)-1 >
2019529628011_ENOCH KWATEH DONGBO_Homework#5 Version 0
👤 Author: by enochdongbogmailcom 2021-12-09 02:07:21
Question: Describe your own case which encounters data inconsistency when processes share data and write the method to solve the problem.

 

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

Reversion History

Loading...
No reversions found.