Answered step by step
Verified Expert Solution
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started