Question: onsider the code shown below for allocating and releasing processes. #define MAX_PROCESSES 255 int number_of_processes = 0; /* the implementation of fork() calls this function

onsider the code shown below for allocating and releasing processes.

#define MAX_PROCESSES 255 int number_of_processes = 0; /* the implementation of fork() calls this function */ int allocate_process() { int new_pid;

if (number_of_processes == MAX_PROCESSES) return -1;

else { /* allocate necessary process resources */ ++number_of_processes;

 return new_pid; } 

}

/* the implementation of exit() calls this function */ void release_process() {

 /* release process resources */ 
 --number_of_processes; } 

a) Identify the race condition(s);

b) Assume you have a mutex lock named mutex with the operations acquire() and release().

Indicate where the locking needs to be placed to prevent the race condition(s).

c) Couldwereplacetheintegervariable:

 int number_of_processes = 0 

with the following atomic integer:

atomic_t number_of_processes = 0 

to prevent the race condition(s)? Motivate your answer.

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!