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