• Keine Ergebnisse gefunden

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 of

i

; 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

Let

v

1,

:::

,

v

m be single-reader,

n

-valued registers, where each

v

i can be written by the same writer and read by process

i

, and construct a single

n

-valued register

v

in which the operation

v

:=

is performed as follows:

for all i in

f1

;:::;m

g

do v

i :=

od

and process

i

reads

v

by reading the value of

v

i. If the

v

i are safe or regular registers, then

v

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 of

v

does not overlap a write of

v

i. If

v

i is safe, then this read gets the correct value, which shows that

v

is safe. If a read of

v

i by process

i

overlaps a write of

v

i, then it overlaps the write of the same value to

v

. This implies that if

v

i is regular, then

v

is also regular.

Construction 1 does not make

v

an atomic register even if the

v

i are atomic. If reads by two dierent processes

i

and

j

both overlap the same write, it is possible for

i

to get the new value and

j

the old value even though the read by

i

precedes the read by

j

|a possibility not allowed by an atomic register.

The next construction is also trivial; it implements an

n

-bit safe register from

n

single-bit ones.

Construction 2

Let

v

1,

:::

,

v

nbe boolean

m

-reader registers, each written by the same writer and read by the same set of readers. Let

v

be the 2n -valued,

m

-reader register in which the number with binary representation

1

:::

n is written by

for all i in

f1

;:::;m

g

do v

i :=

i

od

and in which the value is read by reading all the

v

i. If each

v

i is safe, then

v

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 the

v

i, in which case it obtains the correct values. The register

v

is not regular even if the

v

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

Let

v

be an

m

-reader boolean register, and let

x

be a vari-able internal to the writer (not a shared register) initially equal to the initial value of

v

. Dene

v

to be the

m

-reader boolean register in which the write operation

v

:=

is performed as follows:

if x

6=

then v

:=

;

x

:=

and a read of

v

is performed by reading

v

. If

v

is safe then

v

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 to

n

) until it nds a one. To write the value

, the writer rst sets

v

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

Let

v

1,

:::

,

v

n be boolean,

m

-reader registers, and let

v

be the

n

-valued,

m

-reader register in which the operation

v

:=

is performed by

v

:= 1;

for i

:=

1

step

1

until

1

do v

i := 0

od

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;

while v

= 0

do

:=

+ 1

od

;