Saturday, 17 August 2013

What's the purpose of SignalObjectAndWait regards there is SetEvent and WaitForSingleObject?

What's the purpose of SignalObjectAndWait regards there is SetEvent and
WaitForSingleObject?

I just realized there is SignalObjectAndWait API function for Windows
platform. But there is already SetEvent and WaitForSingleObject, you can
use them together to achieve the same goal as SignalObjectAndWait.
Base on MSDN, the SignalObjectAndWait is more efficient than the other two
function work together, but it also says (so efficient is not the only
reason for why we need WaitForSingleObject):
A thread can use the SignalObjectAndWait function to ensure that a worker
thread is in a wait state before signaling an object.
I doesn't understand this sentence fully, can anybody give some scenario
which SignalObjectAndWait can resolved but SetEvent + WaitForSingleObject
cannot? Thanks.

No comments:

Post a Comment