please use C for the language

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

please use C for the language

Post by answerhappygod »

please use C for the language
Please Use C For The Language 1
Please Use C For The Language 1 (480.21 KiB) Viewed 19 times
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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply