On Thu, Jan 7, 2016 at 1:23 PM, Sebastian Lackner sebastian@fds-team.de wrote:
Wouldn't it be easier to just swap events[0] <-> events[1], to handle the exit event with higher priority? I do not see any real need for two calls to Wait*() functions.
After discussing on irc, we agree that swapping events[0] <-> events[1] is not enough. The original patch fix not only one bug, but two separate problems. In the existent implementation, If ntrc is never set to STATUS_PENDING, then there is no chance to turn exit_now to true, Changhui's patch fix this bug, which is discovered by a real world online bank driver.
Sebastian also pointed out another bug in the existent implementation: halt_event is created as an auto-reset event, which means the first wait*() call could reset it. The correct solution is creating halt_event as manual-reset event instead. It might make sense to create events[0] as manual-reset as well, which makes the following ResetEvent() calls more reasonable.