Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can someone look at this code and tell me what it does and add comments within the code to explain methods #include #include #include #include
Can someone look at this code and tell me what it does and add comments within the code to explain methods
#include
#include
#include
#include
using namespace std;
#define MIN_PID 300
#define MAX_PID 5000
int threadVar = 0;
pthread_mutex_t mutex;
struct pid_tab
{
int pid;
bool bitmap;
}pidArr[4700];
int allocate_map(void) //allocates bitmap values to the data structure
{
int i,j;
for(i = MIN_PID, j =0; i <= MAX_PID; i++, j++)
{
pidArr[j].pid = i;
pidArr[j].bitmap = 0;
}
if(i == MAX_PID && j == 4700)
return 1;
else
return -1;
}
int allocate_pid(void) //allocates a pid to the new process
{
for(int i = MIN_PID, j =0; i <= MAX_PID; i++, j++)
{
if(pidArr[j].bitmap == 0)
{
pidArr[j].pid = i;
pidArr[j].bitmap = 1;
return i;
break;
}
}
return -1;
}
void release_pid(int pid) //releases pid
{
for(int i = 0; i <= 4700; i++)
{
if(pidArr[i].pid == pid)
{
pidArr[i].bitmap = 0;
}
}
}
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