Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use C++ to implement this program. PHASE 1: Scheduler and Semaphore The current system lacks any kind of process management or resource synchronization. This

Please use C++ to implement this program.

PHASE 1: Scheduler and Semaphore The current system lacks any kind of process management or resource synchronization. This problem is clear when two tasks try to use a shared resource such as the screen. In general, the operating system must provide a mechanism for controlling access to any shared resource, such as printer, memory or disk. In addition, we really dont know which task is actually running, which task has been blocked, etc. Our job during this phase is to implement the notion of a binary SEMAPHORE. We must be able to support any number of semaphores. This is critical, since future phases of this project introduce new resources which will certainly need synchronization. In addition to implementing the semaphore, we also need a scheduler with its own process table (more accurately a thread table). The thread table should be implemented dynamically for example a linked list of Task Control Block's (TCB). At this point, the TCB's are needed to preserve the STATE of each Task. For the purpose of this project, we will maintain 4 states: (RUNNING, READY, BLOCKED, DEAD). In the future phases, TCBs will maintain other information such as a pointer to memory allocated by each task, file descriptor, and task priority. One way to implement the Thread Table is to create a TCB for each task when it is being created and insert the task ID, name, and other relevant information in the TCB. Then insert the TCB in a scheduling ring or linked list. int Create_Task(char *task_name, etc...); // return the T_id In short, we need at least two classes. One that implements a scheduling ring and the associated algorithms and the other for implementing semaphores. Develop clear and concise test cases to show how and why your system works. Plan these cases as a group. Each class that you implement must contain one or more debugging functions which print the current state of that class. The overall phase will leverage these debugging functions to show that the phase is working. Class scheduler { TCB *process_table; create_task(); // create appropriate data structures and calls coroutine() destroy_task(); // to kill a task (Set its status to DEAD) yield(); // strict round robin process switch. garbage_collect(); // remove dead task, free their resources, etc. dump(int level); // debugging function with level indicating the verbosity of the dump include some functions which will allow you to dump the contents of the process table in a readable format. See the expected output section (below) for suggestions. } Class semaphore { char resource_name [64]; // the name of the resource being managed int sema_value; // 0 or 1 in the case of a binary semaphore queue *sema_queue; down(); // get the resource or get queued! up() // release the resource dump(int level); // include some functions which will allow you to dump the contents of the semaphore in a readable format. } Suggestions and Hints: Do not use a busy wait in Down (), instead block the task. (check the pThread library) Create a STATE parameter in the Task Control block (TCB) and have the scheduler check to see if a process is ready, blocked, or dead before scheduling. Be aware of deadlocks.

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