In this section, the algorithms for constructing dierent classes of registers are described and informally justied. Rigorous correctness proofs are post-poned until Section 7.
The algorithms are described by indicating how a write and a read are performed. For most of them, the initial state is not indicated|it is the one that would result from writing the initial value starting from any arbitrary state.
The rst construction implements a multireader safe or regular register from single-reader ones. It uses the obvious method of having the writer maintain a separate copy of the register for each reader. The
for all
state-ment denotes that its body is executed once for each of the indicated values ofi
; these separate executions can be done in any order or concurrently.7This is only safe and not regular if, for example, setting a level high when it is already high can cause a perturbation of the level.
Construction 1
Letv
1,:::
,v
m be single-reader,n
-valued registers, where eachv
i can be written by the same writer and read by processi
, and construct a singlen
-valued registerv
in which the operationv
:= is performed as follows:for all i in
f1;:::;m
gdo v
i :=od
and process
i
readsv
by reading the value ofv
i. If thev
i are safe or regular registers, thenv
is a safe or regular register, respectively.The proof of correctness for this construction runs as follows. Any read by process
i
that does not overlap a write ofv
does not overlap a write ofv
i. Ifv
i is safe, then this read gets the correct value, which shows thatv
is safe. If a read ofv
i by processi
overlaps a write ofv
i, then it overlaps the write of the same value tov
. This implies that ifv
i is regular, thenv
is also regular.Construction 1 does not make
v
an atomic register even if thev
i are atomic. If reads by two dierent processesi
andj
both overlap the same write, it is possible fori
to get the new value andj
the old value even though the read byi
precedes the read byj
|a possibility not allowed by an atomic register.The next construction is also trivial; it implements an
n
-bit safe register fromn
single-bit ones.Construction 2
Letv
1,:::
,v
nbe booleanm
-reader registers, each written by the same writer and read by the same set of readers. Letv
be the 2n -valued,m
-reader register in which the number with binary representation 1:::
n is written byfor all i in
f1;:::;m
gdo v
i :=iod
and in which the value is read by reading all the
v
i. If eachv
i is safe, thenv
is safe.This construction yields a safe register because, by denition, a read does not overlap a write of
v
only if it does not overlap a write of any of thev
i, in which case it obtains the correct values. The registerv
is not regular even if thev
i are. A read can return any value if it overlaps a write that changes the register's value from 0:::
0 to 1:::
1.The next construction shows that it is trivial to implement a boolean regular register from a safe boolean register. In a safe register, a read that
overlaps a write may get any value, while in a regular register it must get either the old or new value. However, a read of a safe boolean register must obtain either true or false on any read, so it must return either the old or new value if it overlaps a write that changes the value. A boolean safe register can fail to be regular only if a read that overlaps a write that does not change the value returns the other value|for example, writing the value true when the current value equals true could cause an overlapping read to obtain the value false. To prevent this possibility, one simply does not perform a write that does not change the value.
Construction 3
Letv
be anm
-reader boolean register, and letx
be a vari-able internal to the writer (not a shared register) initially equal to the initial value ofv
. Denev
to be them
-reader boolean register in which the write operationv
:= is performed as follows:if x
6=then v
:=;x
:=and a read of
v
is performed by readingv
. Ifv
is safe thenv
is regular.There are two known algorithms for implementing a multivalued regular register from boolean ones. The simpler one is given as Construction 4; the second one is described later. Construction 4 employs a unary encoding, in which the value
is denoted by zeros in bits 0 through 1 and a one in bit. A reader reads the bits from left to right (0 ton
) until it nds a one. To write the value , the writer rst setsv
to one and then sets bits 1 through 1 to zero, writing from right to left. (While this algorithm has never before been published, the idea of implementing shared data by reading and writing its components in dierent directions was also used in [4].8)Construction 4
Letv
1,:::
,v
n be boolean,m
-reader registers, and letv
be then
-valued,m
-reader register in which the operationv
:= is performed byv
:= 1;for i
:= 1step
1until
1do v
i := 0od
8Although the algorithms in [4] require only that the registers be regular, the assump-tion of atomicity was added because the editor felt that nonatomicity at the level of individual bits was too radical a concept to appear inCommunications of the ACM.
and a read is performed by:
:= 1;