Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Describe the operation of the entry and exit sections to perform the critical se

ID: 3847242 • Letter: D

Question

Describe the operation of the entry and exit sections to perform the critical sections in the figure below. An entry section must satisfy mutual exclusion, progress, bounded waiting. Assume that the lock bit (flag) is addressed at 0x60000000, and the test-and-set function can be implemented in LDREX and STREX instructions in assembly language. LDREX and STREX always cause cache miss, write-through, and they are always used in pairs for a read-modify-write operation. If processor 1 reads data in any memory address using an LDREX instruction, and then processor 2 tries to read data in the same memory address using an LDR or LDREX instruction, the instructions of processor 2 are not executed until processor 1 executes an STREX instruction.


Load lock variable No Unlocked? Yes Try to lock variable using swap: read lock variable and then set variable to locked value (1) No succeed? (m Begin update of shared data Finish update of shared data Unlock: set lock variable to 0 Entry Section Exit Section

Explanation / Answer

Entry Section:

The Entry section is basically used to check whether the process is allowed to execute the critical section.

Generally critical sections holds the code that contain shared resources. So if shared resources are being used by multiple processors at the same time there will be memmory inconsistency and unexpected or incorrect results.So to avoid this scenario multual exclusion is needed. That is if one of the process is executing the critical section then the other processes are to be prevented from executing the critical section.

This can be achieved using the lock mechanism.

Whenever a process want to execute critical section it need to lock that section and then execute the instructions.

For this purpose each critical section is given a lock and whenever a process A want to execute that critical section A will check the lock variable if the lock variable is already set (i.e 1) then it indicate that the critical section is being executed by another process. So this process A keep on reading the lock variable at certain interval of time untill it is zero and when it is zero then A tries to attain the lock by setting the Lock variable, if this succeed then this process A will enter the critical section. If the process of setting lock variable failed then A again tries reading lock variable to check whether it is zero or not.

The process of setting lock fails because there is chance that there is another process P that also waiting to obtain the lock on that particular critical section and if P obtains the lock after A has read lock variable as 0 and before A set the lock variable.So the lock will be assigned to P. Thus again A will be waitng for lock..

This is important as this is where the mutual exclusion is avoided.
Exit Section:

When the process completes the execution of critical section it need to release the lock on that critical section. It releases the lock by setting lock variable to zero. This process is performed in the Exit section. This is also very important because if a process obtained a lock on critical section and after executing the critical section it does not release the lock then other processes which are waiting to enter into critical section will remain in waiting state forever.

--------------------------

If processor 1 and processor 2 are trying to use the same memory location to read data then the first processor that attempted the read will enter to entry section and set the lock sucessfully then read that value and modify it . Meanwhile if processor 2 wants to read the same memmory location then it goes to entry section checks the lock variable and sees that it is alraedy set so it keeps on checking the lock variable. By this time the processor 1 will modify and store the result back to that memmory location and then and goes to Exit section and change the lock variable to zero. now the processor two will see this lock variable as zero and obtains the lock by setting the lock variables and does its work..

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote