Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions