WaitForSingleObject - 线程等待队列吗? [英] WaitForSingleObject - do threads waiting form a queue?

查看:187
本文介绍了WaitForSingleObject - 线程等待队列吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我设置3个线程等待互斥体释放,它们根据他们请求的顺序形成一个队列,或者它是未定义的行为(即我们不知道哪一个会首先拾取它) ?

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 one will pick it up first)?

推荐答案

它在 SDK文章


如果多个线程正在等待互斥量,选择等待线程。不要假定先进先出(FIFO)顺序。外部事件(如内核模式APC)可以更改等待顺序。

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.

这篇关于WaitForSingleObject - 线程等待队列吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆