
372 CHAPTER 5 Shared Memory Multiprocessors
5.19 Suppose we have a machine that supports full-empty bits on every word in hard-
ware. This particular machine allows for the following C code functions:
ST_Special (loc, val) writes val to data location loc and sets the full bit.
If the full bit was already set, a trap is signaled.
int LD_jSpecial (loc) waits until the data location's full bit is set, reads the
data, clears the full bit, and returns the data as the result.
Write a C function swap(ij) that uses these primitives to atomically swap the
contents of two locations
A[i]
and A[j]. You should allow high concurrency (if mul-
tiple processor ...