© Thomas Kunz 2000
SCE 574
110
Mutual Exclusion
(cont.)
äNext attempt:
äBUSY: MOV AL, 80H         ; Prepare to set sem. if not set
ä XCHG AL,SEMPHR  ; Set semaphore & get prev. value
ä OR AL,AL         ; Set flags
ä JNZ BUSY         ; Hang in loop if prev value not 0
ä ....         ; Do whatever
ä MOV SEMPHR,0     ; clear the semaphore
äProblem?
äXCHG requires two memory accesses, so problem can still arise
äSolution
äLOCK instruction
äWhen LOCK is placed in front of an assembler instruction a signal is sent to a CPU pin called LOCK
äLOCK signal remains active for complete duration of a single instruction
äProper wiring of hardware ensures that the other processor will not be able to access the memory location while LOCK is set