Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following code produces a race condition #define MAX_RESOURCES 5 int available_resources = MAX_RESOURCES; When a process wishes to obtain alicense, it invokes the decrease_count()

The following code produces a race condition

#define MAX_RESOURCES 5

int available_resources = MAX_RESOURCES;

When a process wishes to obtain alicense, it invokes the decrease_count() function passing in 1:

// Decrease available_resources by count resources

// return 0 if no resources are available, 1 if successful

int decrease_count(int count) {

if (available_resources >= count) {

available_resources -= count;

return 1;

}

return 0;

}

When a process wants to return a number of resources, it calls increase_count() with the count.

// Increases available_resources by count

void increase_count(int count) {

available_resources += count;

}

1)Identify the locations in the code where the race condition occurs

2)Identify the data involved in the race condition

3)Using a semaphore, fix the race condition. It's okay to modify decrease_count so that the calling process is blocked until sufficient resources are available.

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

Step: 3

blur-text-image

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

Database And Expert Systems Applications Dexa 2022 Workshops 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 In Computer And Information Science 33

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Alfred Taudes ,Atif Mashkoor ,Johannes Sametinger ,Jorge Martinez-Gil ,Florian Sobieczky ,Lukas Fischer ,Rudolf Ramler ,Maqbool Khan ,Gerald Czech

1st Edition

3031143426, 978-3031143427

More Books

Students also viewed these Databases questions

Question

Develop skills for building positive relationships.

Answered: 1 week ago

Question

Describe techniques for resolving conflicts.

Answered: 1 week ago

Question

Give feedback effectively and receive it appropriately.

Answered: 1 week ago