Question: Using the attached code as a starting point add the concept of thread priority as follows: - A thread can be low or high priority

Using the attached code as a starting point add the concept of thread priority as follows:
-A thread can be low or high priority
-Allow creating a low or high priority thread
-Add priority to the info displayed by the display thread feature
-Schedule threads such that all high priority threads run first then low priority threads run. //--------------------------------------
// Basic Thread Scheduler Simulation
//--------------------------------------
#include
#define MAX_THREADS 3
#define IDLE 0
#define READY 1
#define RUNNING 2
#define BLOCKED 3
#define TID int
typedef struct {
TID tid; // Thread ID
int state; // State of the thread
void (*func)(); // Code for the thread
} QCTHREAD;
QCTHREAD threads[MAX_THREADS];
void initThreads()
{
int i;
for (i =0; i < MAX_THREADS; i++)
{
threads[i].tid = i;
threads[i].state = IDLE;
}
}
void displayThreads()
{
int i;
for (i =0; i < MAX_THREADS; i++)
{
printf("tid=%d ", threads[i].tid);
switch (threads[i].state)
{
case IDLE:
printf("IDLE
");
break;
case READY:
printf("READY
");
break;
case RUNNING:
printf("RUNNING
");
break;
case BLOCKED:
printf("BLOCKED
");
break;
}
}
}
void clientCode()
{
printf("Hello from the client application
");
}
TID createThread(void (*threadcode)())
{
int i =0;
int status =0;
while (threads[i].state != IDLE && i

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!