Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6. Consider the code shown below which can be used for allocating resource numbers. For example, it could be used in the kernel to allocate

image text in transcribed

6. Consider the code shown below which can be used for allocating resource numbers. For example, it could be used in the kernel to allocate process numbers. define MAX RESOURCES 5 int resources allocated0 // Allocate a resource to the calling code // Return true if successful, false if unable to allocate Bool allocate_resource(void) if [resources-allocated >=MAX RESOURCES} { return false 10 ) else t resources_allocated+ return truei 12 13 14. 15. 16 // Release the resource void release resource(void) 18 19 20 resources_allocated-- 1. Identify the race condition(s) by describing which piece(s) of code, when running concurrently, can trigger the race condition 2. Assume you have a mutex lock named mutex with operations acquire0 and release0. Indicate where you would need to lock and unlock the mutex. In your answer, you may indicate "between lines 3 and 4" by saying "at line 35 add" 3. Atomic variables are special variable types that ensure that increment, decrement and addition operations are performed atomically. Could the variable at line 2 int resources, allocated- 0; be replaced with an atomic integer variable atomic_t resources_allocated 0 to correctly prevent all race conditions in the code

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 Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

Excel caculation on cascade mental health clinic

Answered: 1 week ago

Question

2. What are your challenges in the creative process?

Answered: 1 week ago