Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Similar to Test-and-set (Atomic exchange) hardware instruction, Compare-And-Swap hardware instruction also reads the 32 bit value from a memory location and set a new value
Similar to Test-and-set (Atomic exchange) hardware instruction, Compare-And-Swap hardware instruction also reads the 32 bit value from a memory location and set a new value to the same memory location as a single atomic instruction. The following are the machine effects in C. int CompareAndSwap(int *ptr, int expected, int new) \{ / atomic read followed by update */ int actual = ptr; if (actual == expected) ptr = new; return actual; \} What is the benefit of using CompareAndSwap over using TestAndSet to implement a lock to enter a critical section (mutual exclusion)? CompareAndSwap requires less number of store instructions. CompareAndSwap requires less number of spin loops. CompareAndSwap works well when the number of CPUs is large. Question 14 4 pts What will be the output when the following program executes? If you need, you can refer to Pthread reference link . \#include pthread.h \#include stdio.h \#include stdlib.h volatile int done =0; void *child(void *arg) \{ printf("- child -"); \} int main(int argc, char *argv[]) \{ printf("- begin -"); pthread_t p; pthread_create(\&p, NULL, child, NULL); printf (" return 0 ; \} either "- begin -- child -- end -" or " - begin -- end -- child -" "- begin -- end -- child -" "- begin -- child -- end -" "- child -- begin -- end
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