2,032 views
0 votes
0 votes
Consider the code example for allocating and releasing processes shown below:

$#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. Could we replace the integer variable int number of processes = 0 with the atomic integer atomic t number of processes = 0 to prevent the race condition(s)?

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
2
0 votes
0 votes
0 answers
3
akash.dinkar12 asked Mar 20, 2019
319 views
Discuss the tradeoff between fairness and throughput of operations in the readers–writers problem. Propose a method for solving the readers–writers problem without ca...
0 votes
0 votes
0 answers
4
akash.dinkar12 asked Mar 20, 2019
241 views
Design an algorithm for a bounded-buffer monitor in which the buffers (portions) are embedded within the monitor itself.