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 are not complete and may have errors). Please note the yellow highlights, It's important that the program performs these functions that are highlighted.
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 ---------------------------------------------------
----------------------------- The output should look exactly like this and then some -----------------------------------------------------------------
------------------- Here is the code I have so far -------------------------------------------------------------
//Declare our variables const int bufferSize = 5; //Number of I/O request for user const int loopAmount = 5; //Total number of IORB
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); //Generating random Driver assignment p(MUTEX1); //Decrement available buffer locations
bufferID = userID; //Passing user and address to shared resources bufferAddress = address;
p(PRINT); cout
v(PRINT); //Gain control of printer v(MUTEX1); //Release control of printer 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); //Send request to User
tempID = bufferID; //Request for user and address tempAddr = bufferAddress;
v(MUTEX1); v(FULL1); //I/O Request
p(FULL2); //Begin producing process and Decrement buffer location p(MUTEX2);
IORQid[a] = tempID; //Passing user and address into shared source IORQaddr[a] = tempAddr;
a = (a + 1) % 5;
p(PRINT); cout
v(PRINT); v(MUTEX2); //Release control of I/O request v(requestPending);
} }
//Driver function void DeviceDriver(){ int b = 0, driverAddress = 0, driverID = 0, a;
for (a = 0; a
p(requestPending); //Check to see if there is a request from DOIO p(MUTEX2);
driverID = IORQid[b]; //Copying user and address to driver driverAddress = IORQaddr[b];
b = (b + 1) % 5;
v(MUTEX2); v(FULL2);
p(FULL3); p(MUTEX3);
track = driverAddress; //Pass address to shared resources
v(MUTEX3); v(PIO);
p(PRINT); cout
v(PRINT); cout
p(operationComplete); //Waiting for disk operation to complete
v(requestService[driverID]); //Inform user request is complete
p(PRINT);
v(PRINT); } }
//Disk function void Disk(){ int a = 0, seek = 0, diskAddress = 0, b;
for (b = 0; b
seek = track; //Gain access to I/O request
v(MUTEX3);
diskAddress = seek * 20;
for (a = 1; a
v(operationComplete); //Inform operation Driver operation is complete
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) 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started