Question: 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

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

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!