Intel i86W Manual page 86

Table of Contents

Advertisement

CORE INSTRUCTIONS
Note that, for each shared data structure, software must establish a single location that is
the first location referenced by any locked sequence that requires that data. For exam-
ple, the head of a doubly linked list should be referenced before accessing items in the
middle of the list.
Example 5-3 shows how
lock
and
unlock
can be used in a variety of interlocked
operations.
Programming Notes
In a locked sequence, a transition to or from dual-instruction mode is not permitted.
II
LOCKED TEST AND SET
II
Value to put in semaphore is in r23
lock
II
ld.b
semaphore, r22
II
Put current value of semaphore in r22
unlock
II
st.b
r23,
semaphore
II
II
LOCKED LOAD-ALU-STORE
lock
II
ld·l
word,
r22
II
addu
1,
r22,
r22
II
Can be any ALU operation
unlock
st·l
r22,
word
II
II
LOCKED COMPARE AND SWAP
II
Swaps r23 with word in memory,
if
word
r21
lock
II
ld.l
word,
r22
II
bte
r22,
r21,
L1
1/
mov
r22,
r23
1/
Executed only if not equal
L1: unlock
1/
st·l
r23,
word
1/
Example
5-3.
Examples of lock and unlock Usage
5-24

Advertisement

Table of Contents
loading

Table of Contents