Question: 3. An implementation of two functions is shown below, one is called inside fork() when creating a new process and the other one is

3. An implementation of two functions is shown below, one is called

3. An implementation of two functions is shown below, one is called inside fork() when creating a new process and the other one is called inside exit() when exiting a process. #define CAPACITY 511 int num_procs - 0; /* inside fork () this function is called */ int assign_proc () { int pid; if (num_proc3 CITY) == return -13; else { /* assign resources to th: process */ num_procs++; return pid; /* inside exit () this function is called void free_proc () { /* free up the resources of this process */ num_procs--: (a) Is there a race condition or race conditions here? Where and why? (b) Suppose there is a lock called lock that's used to provide mutual exclusion and associated with it are the functions acquire () and release (). Where do we need to put them to eliminate the race condition(s)? (c) Recall that an atomic integer in Linux is an integer which have associated math operations that are performed atomically or without interruption, e.g.: atomic_t counter; atomic_inc (&counter); /* counter++: */ atomic_dec (6counter); /* counter--; */ These operations are all atomic, acting on the atomic integer counter. If we change int num_procs = 0; to an atomic integer atomic_t num_procs = 0; Also change the increment of num_procs to atomic_inc () and decrement of num_procs to atomic_dec (). Does this solve the problem of race conditions?

Step by Step Solution

3.43 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

define CAPACITY 511 int numprocs0 inside fork this funciton is called int assignproc int pid ifnumpr... View full answer

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 Programming Questions!