Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a simulator for a functional part of the operating system. Simulator must

ID: 3557720 • Letter: D

Question

Design a simulator for a functional part of the operating system. Simulator must be written in C Language and run in Windows.

Design of a semaphore simulator to manage multiple threads within the some address space 4.1. Evaluation Criteria 4.1.1. Use of ready and blocked queue 4.1.2. Use of semaphore algorithm 4.1.3. Use of process control block 4.1.4. Clear Code with documentation and Comments 4.1.5. Management of multiple random scenarios 4.2. Requirements 4.2.1. Program should ask for amount of processes, and for each process, the type of resources required. 4.2.2. Types of resources should be made available. 4.2.3. At least two processes should use the same type of resource. 4.2.4. Reference (PIT) to each process should be used in the queues. 4.2.5. A process should be placed in the blocked queue when it is waiting for a resource response or when it needs a resource already in use by another process. 4.2.6. Program should store the process context in a process control block. 4.2.7. Programs should move from the ready queue, to the processor, and then to the blocked queue and finally back to the ready queue until completion. 4.2.8. Program should be able to show the queues and semaphore signal status at any moment upon user request. 4.2.9. Resource response may trigger upon pressing a designated key for a resource, which can be changed in the code by the use of macros.

Explanation / Answer

Working code for 2 threads executing on same address using semaphore techniques

/**
* readerWriter.c
* --------------
* The canonical consumer-producer example. This version has just one reader
* and just one writer (although it could be generalized to multiple readers/
* writers) communicating information through a shared buffer. There are two
* generalized semaphores used, one to track the num of empty buffers, another
* to track full buffers. Each is used to count, as well as control access.
*/
#include "thread_107.h"
#include <stdio.h>
#define NUM_TOTAL_BUFFERS 5
#define DATA_LENGTH 20
/**
* Initially, all buffers are empty, so our empty buffer semaphore starts
* with a count equal to the total number of buffers, while our full buffer
* semaphore begins at zero. We create two threads: one to read and one
* to write, and then start them off running. They will finish after all
* data has been written & read. By running with the -v flag, it will include
* the trace output from the thread library.
*/
void main(int argc, char **argv)
{
bool verbose = (argc == 2 && (strcmp(argv[1], "-v") == 0));
Semaphore emptyBuffers, fullBuffers; // semaphores used as counters
char buffers[NUM_TOTAL_BUFFERS]; // the shared buffer
InitThreadPackage(verbose);
emptyBuffers = SemaphoreNew("Empty Buffers", NUM_TOTAL_BUFFERS);
fullBuffers = SemaphoreNew("Full Buffers", 0);
ThreadNew(

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote