. , , ,

,,,

,


, , , (Dijkstra) 1965 . , . , , .

. , ( ), . , , . , .

, ( proberen ) V ( verhogen ). S . V(S) P(S) :

P(S):

S = 0

;

S = S 1;

V(S): S = S + 1;

:

- P S . 0, S 1.

0, , S 0, S 1. .

- V S 1. S .

V .

, , producer-consumer (-).

. N , .

- , - . - - , , - .

- , , . , - , , .

: , f , = N, a f = 0. (.1).

- (), , . , 0 (.. ), - .


, , V(f). - , , , .

. , WaitForSingleObject() WaitForMultipleObject().

Win32 I, . , ( ) , . .

, ( ), , - , .

, ( ) . (, ).

Win32 WaitForSingleQbject(), :

DWORD WaitForSingleObject(HANDLE handle, DWORD timeout);

:

handle ;

timeout ( INFINITE ).

: WaitForSingleObject() : WAIT_OBJECT_0 - ; WAIT_TIMEOUT - ( timeout INFINITE), .

, ( ). WaitForMultipleObjects():

DWORD WaitForMultipleObjects(DWORD count, CONST HANDLE handles, BOOL waitall, DWORD timeout);

:

count ;

handles ( INFINITE ).

waitall ;

timeout WaitForSingleObject

:

handles count ( 64 ). waitall.

-    waitall TRUE, . , WAIT_OBJECT_0.

-    waitall FALSE, . , WAIT_OBJECT_0+i, i- handles.

, , , WaitForSingleObject(), . , .

, . , WaitForSingleObject() WaitForMultipleObject(), ReleaseSemaphore().

, . , .

. , , . .

WaitForSingleObject() , , .

, WaitForSingleObject() , .

, , WaitForSingleObject() , . , , , .

?

, , ReleaseSemaphore(). , .

Windows, .

, , CreateSemaphore(), .

HANDLE CreateSemaphore (LPSECURITY_ATTRIBUTES lpThreadSecurity, LONG lSemInitialCount, LONG lSemMaxCount, LPCTSTR lpszSemName)

:

lpThreadSecurity , . , , NULL;

lSemInitialCount , lSemMaxCount;

lSemMaxCount . ;

lpszSemName , . , ;

. , NULL.

CloseHandle(). , .

, , , lpszSemName CreateSemaphore() NULL.

, , . CreateSemaphore, , .

OpenSemaphore(),

HANDLE OpenSemaphore (DWORD dwAccessFlag, BOOL bInherit, LPCTSTR lpszSemName)

:

dwAccessFlag ;

bInherit , CreateProcess();

lpszSemName , .

. , NULL.

:

SEMAPHORE_ALL_ACCESS
SEMAPHORE_MODIFY_STATE ReleaseSemaphore()
SYNCHONIZE

ReleaseSemaphore(),

BOOL ReleaseSemaphore (HANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviosCount)

:

hSemaphore ;

lReleaseCount , , ;

lpPreviosCount .

. TRUE, NULL.

ReleaseSemaphore() , hSemaphore, , lReleaseCount.

, lReleaseCount , .

, , ReleaseSemaphore() .

, ReleaseSemaphore(), LONG. lpPreviousCount.

, :

-, , . .

-, .

, , , . ReleaseSemaphore() , .

Windows , .

, , WaitForSingleObject() WaitForMultipleObject(). , .

, :

-     CreateSemaphore() OpenSemaphore() ;

-     WaitForSingleObject() , , . , , ;

-     ReleaseSemaphore(), .

ReleaseSemaphore() , , , ReleaseSemaphore() lplPreviousCount.

, (, , ).

, , , (Dijkstra) 1965 . ,

 

 

 

! , , , .
. , :