.


:




:

































 

 

 

 


-

.

1. (N), , .

procedure INIT; common integer N;

Begin N: =1; start (P1); start (P2); end;

Process P1; common integer N;

Begin while true do begin BEFORE1; while N=2 do; CS1; N: =2; AFTER1; end; end;

Process P2; common integer N;

Begin while true do begin BEFORE2; while N=1 do; CS2; N: =1; AFTER2; end; end;

, : , , , , , , .. .

2. -, , , .

Procedure INIT; common Boolean C1, C2;

Begin C1:=false; C2:=false; start (P1); start (P2); end;

Process P1; common Boolean C1, C2;

Begin while true do begin BEFORE1; while C2 do; C1:=true; CS1; C1:=false; AFTER1; end; end;

Process P2; common Boolean C1, C2;

Begin while true do begin BEFORE2; while C1 do; C2:=true; CS2; C2:=false; AFTER2; end; end;

, . , - .

3.

, , . , .

Procedure INIT; common Boolean C1, C2; common integer N;

Begin C1:=false; C2:=false; N: =1; start (P1); start (P2); end;

Process P1; common Boolean C1, C2;

Begin while true do begin BEFORE1; C1:=true; while C2 do begin if N=2 then begin C1:=false; while N=2 do; C1:=true; end; end; CS1; C1:=false; N: =2; AFTER1; end; end;

Process P2; common Boolean C1, C2;

Begin while true do begin BEFORE2; C2:=true; while C1 do begin if N=1 then begin C2:=false; while N=1 do; C2:=true; end; end; CS2; C2:=false; N: =1; AFTER2; end; end;

 

- , .

P (d) - , .. , V (d) , .

.

(Binary Semaphore) - 2 : (0-, 1-).

(Integer Semaphore) - :

1) : . , S>0 (.. ). S=0 .

2) : , .

 

-.

, n 1- . , , . , , 1 . . . 2 , , 1 .

INIT: Binary Semaphore B; Integer Semaphore E, F; F: =1; E: =N; B: =1; Start (W); Start(R); end;

Process W: begin while true do begin P(B); P(E); V(B); V(F) { }; end; ; end;

Process R: begin while true do begin P(F); P(B); Read(P) { , }; V(B); V(E) { }; end; ; end;

 

WinNT.

1. . . WaitForSingleObject - . , ( ) . WAIT_OBJECT_0 ; WAIT_TIMEOUT ; WAIT_ABANDONED ( Mutex).

2. . . - CreateEvent, , . . , OpenEvent. - SetEvent, ResetEvent PulseEvent. , () , WaitForSingleObject WaitForMultipleObject. CloseObject.

3. Mutex. , . -, . . WaitForSingleObject WaitForMultipleObjects.

4. . - : (). , , , - , , . , .

 



<== | ==>
| : ,
:


: 2016-09-06; !; : 480 |


:

:

- , .
==> ...

1893 - | 1693 -


© 2015-2024 lektsii.org - -

: 0.009 .