Question about Win32 ## Event ## synchronization object

First let me introduce an application scene:

I have a utility application that tracks the status of something, and also has several applications awaiting a status change. After changing the status, each application will read the status value (through the named FileMap object) and perform the appropriate actions, and then wait until the status is changed again.

So I used an Event object named named to do the synchronization. All applications wait for this event to be signaled, and the service application will set this event to signal when this status is changed.

I need to ensure that when the status changes, each pending application will be released , and will be released only once !

I tried these 2 methods

Method 1

  • Create a manual reset event;
  • When the status is changed, first call SetEvent, and then immediately call ResetEvent.

Method 2

  • Create a manual reset event;
  • When the status is changed, call the PulseEvent function.

Both methods work well during the test. But I think that none of them is reliable, because:

For ## Method 1 ##, it is possible that some of the pending threads will not have a chance to be executed before calling the ResetEvent function.

For ## Method 2 ##, Microsoft stated PulseEvent is unreliable and should not be used .

Is there any workable solution for this case? Any advice is appreciated.

+3
3

O (1).

N , N . , reset .

, , N WaitForMultipleObjects bWaitAll == TRUE. .

, : , , A, B-, reset B, . : A (i) , reset A (i), , B (i), .

A B . reset -.

, - B. , (B '), . , B, B ', , N. , B (i), , , B '.

A. A, . A (i), . .

, . , , .

+1

# 1 ( , ) , , " " - , , , SetEvent(), , , ResetEvent(). ResetEvent() , ( ).

, SetEvent()/ResetEvent(), "" . , , . reset, , SetEvent()/ResetEvent() main, reset.

, " ". , - , ( , )? if SetEvent() , , , , ? .

+1

- !

, , . auto- reset . . , . , /. . , , , .

, , , - (, ), , , .

- reset ( ResetEvent Pulse)

, . ☺

, PulseEvent . 32- Windows NT - 3.1. , , .

, auto-reset. auto- reset : CreateEvent bManualReset ( TRUE, manual-reset, ResetEvent - , ). FALSE, auto- reset, , , , WaitForMultipleObjects WaitForSigleObject. auto- reset ResetEvent ( reset) PulseEvent ( ).

, Microsoft , PulseEvent - . https://msdn.microsoft.com/en-us/library/windows/desktop/ms684914(v=vs.85).aspx - , PulseEvent. - , , , . , APC. PulseEvent , , , PulseEvent , , . (APC) :

PulseEvent - auto- reset - Windows NT 3.51, , .

, . , , . , (!) auto- reset. . , , . , , . , , SetEvent . , . , - , SendMessage, , FileMap. , , SendMessage . , SendMessage . - YourAppNameEvent1, YourAppNameEvent2 .. , CreateEvent auto- reset , OpenEvent . - , , SendMessage, , CloseHandle , ( CloseHandle - , ). , , , CloseHandle, - , - 2 ^ 24. - , , , , , SetEvent . - , . , , , , , . , .

0
source

Source: https://habr.com/ru/post/1777857/


All Articles