Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
I need explanation ND code CSC 432 Lab 2 Instructions: The example program given below in this lab creates a race condition if two instances
I need explanation ND code
CSC 432 Lab 2 Instructions: The example program given below in this lab creates a race condition if two instances of it are run concurrently. You must eliminate the race condition by following these three steps: 1. a. Identify the critical section and remainder section of the program. b. Use the swap instruction to create a spinlock to pregent both processes executing in their critical sections at the same time. Explain the limitation of this solution. c. RRISC [Radically Reduced Instruction Set Computer Instructions: I. register-+value Sets the value register to be value. Value can be any positive integer 2. register-@index Sets the value of register to be sharedMemory[index]. 3. registerx +register. Increases registerx by registery 4. @index- register Sets the value of sharedMemory[index] to be register. 5. register ?linenumber If register is non-zero, go to the instruction on line linenumber. Note that the first line number in a program is line number 0. 6. register @index Swaps the values stored in register and sharedMemory index print register Prints out register to standard output. 7. View Tools Help View only register ?1inenumber If register is non-zero, go to the instruction on line linenumber. Note that the first line number in a program is line number o. 5. 6. register @index Swaps the values stored in register and sharedMemory[index] 7. print register Prints out register to standard output. Notes: 1. There are three registers: ri. r2, and r3. 2. There are 16 shared memory indexes from 0 to 15 3. The register r- always equals -1 and cannot be written to. 4. The register rz always equals 0 and cannot be written to. Example Program: Comments are not allowed in the language but are added here to aid understanding. Code is written using Courier New font and comments are written in Times New Roman font. r1 +10 load the value 10 into register r1. r3 = +1 load the value l into register r3. r1 += r- decrement ri (increase rl by-1). r2 = @o load the shared memory value at index o into r2. 2 r3 increment r2 80 r2 store the value in register r2 back to shared memory address 0. ri ? 2 r2 = @0 load the shared memory value at index 0 into r2 print r2 print out the value in r2. while rl isn't 0 goto line 2 (ifrl is non-zero goto line 2)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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