Question
PLEASE ANSWER IN C-- NOTTTTTTT C! I AM AWARE OF THE OTHER ANSWERS TO THIS--DUPLICATE ANSWER WILL GET A THUMBS DOWN AND WILL BE FLAGGED.
PLEASE ANSWER IN C--
NOTTTTTTT C!
I AM AWARE OF THE OTHER ANSWERS TO THIS--DUPLICATE ANSWER WILL GET A THUMBS DOWN AND WILL BE FLAGGED.
1.- In this assignment you will implement a simulation of the interaction of user programs
with the OS to execute an I/O operation.
User programs:
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 two parameters: User id 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 two buffers of size one each (bufid and bufaddr).
Once the parameters are stored in the buffers, user programs executes a P(request served) operation to wait for the completion of the I/O operation. There will be only one user running and it will execute 5 I/O operations.
DOIO:
DOIO will collect an id and address(addr) from bufid and bufaddr to assemble the IORB. DOIO will store the IORB (id and addr) into two buffers that represent the IORQ (iorqid and iorqaddr).
Device driver:
Device driver will collect an IORB (pair id and addr) from iorqid and iorqaddr and then initiates the physical I/O operation on the hard drive and wait for the I/O operation to be completed: P(operation complete).
The device driver initiate the physical I/O operation by storing addr into a buffer of length one. The buffer name is pio (physical I/O).
When the I/O operation completes a signal is received, the driver will identify the user that issued the I/O request using the id, and will signal the semaphore request served associated to the user.
Disk:
The disk process simulates the access to a track in the hard drive.
The Disk process gets the addr from pio and stores it in a variable called seek and iterates in a dummy loop from 1 to seek. Once out of the loop, disk will execute a V on the semaphore operation complete
a) Define all semaphores that you need according to the number of buffers used.
The user will make 5 system calls to initiate I/O operations
DOIO will create 5 IORB
Project Direction
You will write a C-- program based on the BACI interpreter.
___________________BELOW IS MY CURRENT PROGRAM...which keeps hitting a deadlock error and it doesn't follow directions to the t (used google and youtube) so I need help fixing this..._________________________________________________________________________________________________________________
const int bufferSize = 5; const int loopAmount = 25;
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;
void User (int userID) { int i, j, address = 0; for(j = 0; j < bufferSize; j++){ address = random(i+1) % 200; p(FULL1); p(MUTEX1); bufferID = userID; bufferAddress = address; p(PRINT); cout << "User " << userID + 1 << " executes system call SIO" << endl; v(PRINT); v(MUTEX1); v(SIO); p(requestService[userID]); } }
void DOIO() { int i = 0, tempID, tempAddr, index;
for (index = 0; index < loopAmount; index++){ p(SIO); p(MUTEX1);
tempID = bufferID; tempAddr = bufferAddress; v(MUTEX1); v(FULL1);
p(FULL2); p(MUTEX2);
IORQid[i] = tempID; IORQaddr[i] = tempAddr;
i = (i+1) % 5;
p(PRINT); cout << "DOIO assembles IORB for user " << tempID + 1 << " and inserts it in IORQ" << endl; v(PRINT);
v(MUTEX2); v(requestPending); }
}
void DeviceDriver() { int j = 0, driverAddress = 0, driverID = 0, i; for (i = 0; i < loopAmount; i++){ p(requestPending); p(MUTEX2);
driverID = IORQid[j]; driverAddress = IORQaddr[j];
j = (j+1) % 5;
v(MUTEX2); v(FULL2); p(FULL3); p(MUTEX3);
track = driverAddress; v(MUTEX3); v(PIO);
p(PRINT); cout << "Driver initiates I/O operation for user " << driverID + 1<< endl; v(PRINT);
p(operationComplete); v(requestService[driverID]);
p(PRINT); cout << "Driver signal user " << driverID + 1 <<" (operation complete)"<< endl; v(PRINT); } }
void Disk() { int i = 0, seek = 0, diskAddress = 0, j; for (j = 0; j < loopAmount; j++){ p(PIO); p(MUTEX3); seek = track; v(MUTEX3); diskAddress = seek * 20; for (i = 1; i <= diskAddress; i++){} //Dummy Loop v(operationComplete); p(PRINT); cout << "Disk Completes I/O operation (disk does not know what process initiated the I/O operation)" << endl; v(PRINT); v(FULL3); } }
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);
cobegin { User(0); DOIO(); DeviceDriver(); Disk();
} }
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