This course is run at the The University of Nottingham within the School of Computer Science & IT. The course is run by Graham Kendall (EMAIL : gxk@cs.nott.ac.uk)
This assembly (like) code shows how we can make use of the TSL instruction to solve the mutual exclusion problem.
enter_region:
tsl register, flag ; copy flag to register and set flag to 1
cmp register, #0 ;was flag zero?
jnz enter_region ;if flag was non zero, lock was set , so loop
ret ;return (and enter critical region)leave_region:
mov flag, #0 ; store zero in flag
ret ;return
Assume, again, two processes.
Process 0 calls enter_region. The tsl instruction copies the flag to a register and sets it to a non-zero value. The flag is now compared to zero (cmp - compare) and if found to be non-zero (jnz - jump if non-zero) the routine loops back to the top. Only when process 1 has set the flag to zero (or under initial conditions), by calling leave_region, will process 0 be allowed to continue.
Last Page | Back to Main Index | Next Page |
Last Updated : 14/01/2002