Assume you have done all your synchronization for a large project on an architec
ID: 3685214 • Letter: A
Question
Assume you have done all your synchronization for a large project on an architecture which has a hardware implementation of thetest_and_set function and it is all based on this function as the smallest unit of atomicity.
You have to now port the code to an architecture that does not have the guarantee of atomicity. How can you modify your code so that with minimal effort you can get the code to work again, maybe not as efficiently?
boolean test_and_set (boolean *target) { disable_interrupts(); boolean rv = *target; *target = TRUE; enable_interrupts(); return rv; }
Explanation / Answer
boolean test_and_set (boolean *target) { return (boolean) compare_and_swap(target, *target, !(*target)); }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.