- 3


flag[ i ] = TRUE;

turn = i;

while (turn = = i && flag[ other ] = = TRUE) /* */;

}

 

void leave_region(

int i )

{

flag[ i ] = FALSE;

}

 

TEST_and_SET_LOCK.

TSL(r,s): [r = s; s = 1]

- .

enter_region:

tsl reg, flag

cmp reg, #0 /* */

jnz enter_region /* - */

ret

leave_region:

mov flag, #0 /* */

ret

(1965).

- , :

P(s):

[if (s == 0) < >;

else s = s-1;]

V(s):

[if (s == 0) < >;

s = s+1;]

 

 

().

-.

- (-, ).

semaphore s = 1;

semaphore full = 0;

semaphore empty = N;

 

producer() consumer()

{ {

int item; int item;

while (TRUE) while (TRUE)

{ {

produce_item(&item);

P(empty); P(full);

P(s); P(s);