please use C for the language
Problem C. Use the atomic compare_and_swap instruction to fix the race condition in Problem A. a. Write a C statement to declare and initialize a shared variable lockTop, whose value is -1 when unlocked and 0 when locked b. Re-write the push() function to call the compare_and_swap () function defined in the PPT Slide 3.18 for Section III c. Re-write the pop () function to call the compare_and_swap () function defined in the PPT Slide 3.18 for Section III (Hint: other than the end of a function, the return statement also deserves some attention.) d. Does this solution satisfy the mutual-exclusion requirement? Does it satisfy the bounded-waiting requirement? Referenced Information Below compare_and_swap Instruction Definition: int compare_and_swap (int *value, int expected, int new_value) { int temp = *value; if (*value == expected) *value = new_value; return temp; } 1. Executed atomically 2. Returns the original value of passed parameter "value" 3. Set the variable "value" the value of the passed parameter "new_value" but only if "value" =="expected". That is, the swap takes place only under this condition.
please use C for the language
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am