怎么得知一个核心对象是否处于激发状态
如何得知一个核心对象是否处于激发状态?
是否只能这样:
通过WaitForSingleObject(),将等待时间dwMilliseconds参数设为0,判断返回值:
WAIT_OBJECT_0:激发状态 WAIT_TIMEOUT:未激发状态
想请教一下各位大侠平时怎么做的?
我有另一个 线程会Reset这个内核对象,另有一个任务线程,如果这个内核对象是激活的,那么不做动作,如果未激活,则会激发它。
------解决方案--------------------
好像是的。
但使用的时候得小心,特别是一些自动事件或者互斥量,是有副作用的。简单说就是调用WaitForSingleObject会由激活状态转为未激活状态。
如果这个内核对象是激活的,那么不做动作,如果未激活,则会激发它。
我觉得你这样的逻辑有点问题,感觉怪怪的。
------解决方案--------------------
《Windows核心编程》
Synchronization Functions
The following functions are used in synchronization.
CancelWaitableTimer
CreateEvent
CreateMutex
CreateSemaphore
CreateWaitableTimer
DeleteCriticalSection
EnterCriticalSection
GetOverlappedResult
InitializeCriticalSection
InitializeCriticalSectionAndSpinCount
InterlockedCompareExchange
InterlockedDecrement
InterlockedExchange
InterlockedExchangeAdd
InterlockedIncrement
LeaveCriticalSection
MsgWaitForMultipleObjects
MsgWaitForMultipleObjectsEx
OpenEvent
OpenMutex
OpenSemaphore
OpenWaitableTimer
PulseEvent
QueueUserAPC
ReleaseMutex
ReleaseSemaphore
ResetEvent
SetCriticalSectionSpinCount
SetEvent
SetWaitableTimer
SignalObjectAndWait
TimerAPCProc
TryEnterCriticalSection
WaitForMultipleObjects
WaitForMultipleObjectsEx
WaitForSingleObject
WaitForSingleObjectEx
------解决方案--------------------
If dwMilliseconds is zero, the function tests the object's state and returns immediately.
------解决方案--------------------
不需要检测的, 直接 Signal 。
是否只能这样:
通过WaitForSingleObject(),将等待时间dwMilliseconds参数设为0,判断返回值:
WAIT_OBJECT_0:激发状态 WAIT_TIMEOUT:未激发状态
想请教一下各位大侠平时怎么做的?
我有另一个 线程会Reset这个内核对象,另有一个任务线程,如果这个内核对象是激活的,那么不做动作,如果未激活,则会激发它。
------解决方案--------------------
好像是的。
但使用的时候得小心,特别是一些自动事件或者互斥量,是有副作用的。简单说就是调用WaitForSingleObject会由激活状态转为未激活状态。
如果这个内核对象是激活的,那么不做动作,如果未激活,则会激发它。
我觉得你这样的逻辑有点问题,感觉怪怪的。
------解决方案--------------------
《Windows核心编程》
Synchronization Functions
The following functions are used in synchronization.
CancelWaitableTimer
CreateEvent
CreateMutex
CreateSemaphore
CreateWaitableTimer
DeleteCriticalSection
EnterCriticalSection
GetOverlappedResult
InitializeCriticalSection
InitializeCriticalSectionAndSpinCount
InterlockedCompareExchange
InterlockedDecrement
InterlockedExchange
InterlockedExchangeAdd
InterlockedIncrement
LeaveCriticalSection
MsgWaitForMultipleObjects
MsgWaitForMultipleObjectsEx
OpenEvent
OpenMutex
OpenSemaphore
OpenWaitableTimer
PulseEvent
QueueUserAPC
ReleaseMutex
ReleaseSemaphore
ResetEvent
SetCriticalSectionSpinCount
SetEvent
SetWaitableTimer
SignalObjectAndWait
TimerAPCProc
TryEnterCriticalSection
WaitForMultipleObjects
WaitForMultipleObjectsEx
WaitForSingleObject
WaitForSingleObjectEx
------解决方案--------------------
If dwMilliseconds is zero, the function tests the object's state and returns immediately.
------解决方案--------------------
不需要检测的, 直接 Signal 。