Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you explain what this code does. step by stpe in detailed explanation. please and thank you ************************************************************************************* semaphore full; semaphore full2; semaphore full3; semaphore

Can you explain what this code does. step by stpe in detailed explanation.

please and thank you

*************************************************************************************

semaphore full; semaphore full2; semaphore full3; semaphore sio; semaphore request_served; semaphore opc; semaphore rpend; semaphore PIO;

binarysem mutex; binarysem mutex2; binarysem mutex3; //arrays int bufid[1]; int bufaddr[1]; int iorqid[5]; int iorqaddr[5]; int pio[1];

int addr;

void user() { int i=0; int id=1; int loop; for(loop=0;loop<5;loop++) { addr=random(20)+1; p(mutex); bufid[i]=id; bufaddr[i]=addr; cout<<"User "<

v(mutex); v(sio);

p(request_served); }

}

void doio() { int i=0; int k=0; int did; int daddr; int loop; for(loop=0;loop<5;loop++) { p(sio); p(mutex);

did=bufid[k]; daddr=bufaddr[k]; v(mutex); v(full);

p(full2); p(mutex2);

iorqid[i]=did; iorqaddr[i]=daddr; i=(i+1)%5; cout<<"DOIO assembles IORB and inserts it in IORQ"<

v(mutex2); v(rpend); } }

void deviceDriver() { int i=0; int k=0; int ddid; int ddaddr; int loop;

for(loop=0;loop<5;loop++) { p(rpend); p(mutex2);

ddid=iorqid[i]; ddaddr=iorqaddr[i]; i=(i+1)%5; v(mutex2); v(full2);

p(full3); p(mutex3);

pio[k]=ddaddr; cout<<"Driver initiates I/O operation for user "<

v(mutex3); v(PIO); p(opc);

cout<<"Driver signal user "<

}

void disk() { int seek; int i=0; int loop; int c;

for(loop=0;loop<5;loop++) { p(PIO); p(mutex3);

seek=pio[i]; cout<<"Disk Completes I/O operation "<<"(disk does not know what process initiated the I/O operation)"<

v(mutex3); v(full3); for(c=1;c

void main() {

initialsem(mutex,1); initialsem(mutex2,1); initialsem(mutex3,1); initialsem(full,1); initialsem(full2,5); initialsem(full3,1); initialsem(sio, 0); initialsem(request_served, 0); initialsem(rpend, 0); initialsem(opc, 0); initialsem(PIO,0);

cobegin { user(); doio(); deviceDriver(); disk(); }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What are the types of forms of communication ?

Answered: 1 week ago

Question

Explain the process of MBO

Answered: 1 week ago

Question

5. Arranging for the training facility and room.

Answered: 1 week ago