Question: Hello. Can someone please help me with this program. It is written in C-- based on the BACI interpreter. First I will post the instructions

Hello. Can someone please help me with this program. It is written in C-- based on the BACI interpreter. First I will post the instructions and then I will post the codes that I have so far (which doesn't perform the functions highlighted and may have errors).

Please note the yellow highlights, It's important that the program performs these functions that are highlighted as well.

And also, please include comments so that I can better understand how each function works.

Thank you in advance!

----------------- Below are the instructions on how the program should perform ---------------------

Hello. Can someone please help me with this program. It is written

in C-- based on the BACI interpreter. First I will post the

instructions and then I will post the codes that I have so

--------- Here is the code I have so far (Please don't repost this as the answer!)--------------------------

//Declare our variables const int bufferSize = 5; const int loopAmount = 5;

semaphore FULL1, FULL2, FULL3; semaphore MUTEX1, MUTEX2, MUTEX3; semaphore PRINT; semaphore PIO, SIO; semaphore operationComplete; semaphore requestPending; semaphore requestService[bufferSize];

int IORQid[bufferSize]; int IORQaddr[bufferSize]; int bufferAddress = 0, bufferID = 0, track = 0;

//Function to intialize user to execute system call void User (int userID){ int a, b, address = 0;

for(b = 0; b

p(FULL1); p(MUTEX1);

bufferID = userID; bufferAddress = address;

p(PRINT); cout

v(PRINT); v(MUTEX1); v(SIO);

p(requestService[userID]);

} }

//Function for assembly and insertion void DOIO(){ int a = 0, tempID, tempAddr, index;

for (index = 0; index

p(SIO); p(MUTEX1);

tempID = bufferID; tempAddr = bufferAddress;

v(MUTEX1); v(FULL1);

p(FULL2); p(MUTEX2);

IORQid[a] = tempID; IORQaddr[a] = tempAddr;

a = (a + 1) % 5;

p(PRINT); cout

v(PRINT); v(MUTEX2); v(requestPending);

} }

//Driver function void DeviceDriver(){ int b = 0, driverAddress = 0, driverID = 0, a;

for (a = 0; a

p(requestPending); p(MUTEX2);

driverID = IORQid[b]; driverAddress = IORQaddr[b];

b = (b + 1) % 5;

v(MUTEX2); v(FULL2);

p(FULL3); p(MUTEX3);

track = driverAddress;

v(MUTEX3); v(PIO);

p(PRINT); cout

v(PRINT); cout

p(operationComplete);

v(requestService[driverID]);

p(PRINT);

v(PRINT); } }

//Disk function void Disk(){ int a = 0, seek = 0, diskAddress = 0, b;

for (b = 0; b

seek = track;

v(MUTEX3);

diskAddress = seek * 20;

for (a = 1; a

v(operationComplete);

p(PRINT); cout

v(PRINT); v(FULL3); //Release control of disk } }

//Main function for initialization of request main (){

initialsem (MUTEX1, 1); initialsem (MUTEX2, 1); initialsem (MUTEX3, 1); initialsem (PRINT,1); initialsem (FULL1, 1); initialsem (FULL2, 5); initialsem (FULL3, 1); initialsem (SIO, 0); initialsem (PIO, 0); initialsem (requestPending, 0); initialsem (operationComplete, 0); initialsem (requestService[0], 0); initialsem (requestService[1], 0); initialsem (requestService[2], 0); initialsem (requestService[3], 0); initialsem (requestService[4], 0);

cobegin{ User(0); DOIO(); DeviceDriver(); Disk(); } }

User programs will communicate with DOIo (OS) to request an I O operation. (This will simulate a system call) User programs will give to DOIO three parameters. User id, device number dev is a random number in the range 1 and 2 that represents device one or device two) and an address (addr is a random number in the range 1 and 20.) (addr is an integer that represents a track number in the hard drive).| User programs will pass the parameters to DOIO through three buffers of size one each (bufid, bufdev, and bufaddr) Once the parameters are stored in the buffers, user programs executes a p request served?index" ]) operation to wait for the completion of the IO operation. You will need a semaphore array request served[5] There will be five users running concurrently and each will execute 5 IO operations DOIO: DOIO will collect and id, device(dev), and address(addr) from bufid, bufdev, and bufaddr to assemble the IORHB DOIO will check on device number to decide which one of the two devices will get the IORB Once the device has been selected, DOIO will store the IORB (id and addr) into the two buffers that represent the IORO (iorgid and iorgaddr) of the selected device. Notice that you need separate buffers (one for each device: iorgid and iorgaddr and iorqid2 and iorqaddr2)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!