Question: 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

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!