Problem 2. Use compare_and_swap(), an atomic hardware instruction… Problem 2. Use compare_and_swap(), an atomic hardware instruction to fix the race condition and solve the critical section problem in the code given below. void push(int item) { if (top < SIZE) { stack[top] = item; // LINE A top++; // LINE B } else ERROR //no return or exit } int pop() { if (top > 0) { top–; // LINE X return stack[top]; // LINE Y } else { ERROR //no return or exit return -1; } } a. Write 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 c. Re-write the pop() function to call the compare_and_swap() function defined in the PPT Slide 3.18 (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? here is slide 3.18Image transcription textcompare_and_swap: an Atomic Hardware 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. Executedatomically 2. Returns the original value of passed parameter “value” 3. Set the variable … Show more… Show more Engineering & Technology Computer Science CS 3600
You will get a plagiarism-free paper and you can get an originality report upon request.
All the personal information is confidential and we have 100% safe payment methods. We also guarantee good grades
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more