WaitForSingleObject - do threads waiting form a queue?

后端 未结 5 577
庸人自扰
庸人自扰 2021-01-18 06:04

If I set 3 threads to wait for a mutex to be release, do they form a queue based on the order they requested it in or is it undefined behaviour (i.e. we don\'t know which on

5条回答
  •  渐次进展
    2021-01-18 06:22

    It is explicitly documented in the SDK article:

    If more than one thread is waiting on a mutex, a waiting thread is selected. Do not assume a first-in, first-out (FIFO) order. External events such as kernel-mode APCs can change the wait order.

    These kind of events are entirely out of your control. So "undefined behavior" is an appropriate way to describe it.

提交回复
热议问题