MSDN上明确写道:“Therefore, PulseEvent is unreliable and should notbe used by new applications. Instead, use condition variables.”,MSDN给的理由是:“A thread waiting on asynchronization object can be momentarily removed from the wait state by akernel-mode APC, and then returned to the wait state after the APC is complete.”
然而,在某些scenarios中,PulseEvent还是有用的。例如:我们有一个WinCE上的项目,软件里的一个worker thread1通过串口向硬件发送一个命令后会阻塞等待硬件给出回应(ACK),而另一个worker thread2会接受并处理硬件通过串口发来的各种数据,包括ACK信息。由于thread2处理信息时可能导致ACK处理的滞后,此时thread1的阻塞等待状态可能已经time out,并且可能马上要进入到下一个阻塞等待状态。这种情况下,PulseEvent可以替我们缓解一下ACK错误匹配的问题。
当然,应该注意的是:PulseEvent在上述场合下的作用只是一个缓解,问题的根本解决可能需要重新的设计或不存在一个100%正确的解决方案。但是,这却是一个事实存在,而且很可能不是唯一的。