多线程等待对象 [英] Multithreading Waitable Object

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

问题描述

嗨 目前,我正在阅读一些多线程问题.有一个共同的描述
除关键部分外的同步对象"中的所有其他对象都是可以等待的.

这种术语使人们感到困惑,因为
1.所有需要资源的线程都在CS上被阻塞,等到CS释放.
2.其他所有同步对象也是如此.

还是为什么CS被称为不可等待
和其他真正的等待对象.

问候
kanade

Hi Currently I am reading some Multithreading issues. There is a common description
of the ''Synchronization Objects'' that except Critical Section all other objects are waitable.

This terminology is creating confusion as
1. All the threads who want a resource get blocked on CS and wait till the CS is released.
2. Same is the situation with all other synchronization objects as well.

Still why CS is called as not waitable
and other as true waitable objects.

regards
kanade

推荐答案

这是某些文档中我不能负责的术语.

我只是看了一些物体,以为可以看到区别.以我的口味,这确实是次要的.有一种简化使临界区"有所不同.它可以被认为是Mutex的轻量级版本.它具有简化的接口,只能用于同一进程的线程之间的同步,而不能用于不同进程的线程之间的同步.

首先,同步对象"原语使线程处于特殊的等待状态. OS会将进入关键部分或等待其他同步对象的线程切换出去,直到被某个中断条件唤醒后,该线程才将其调度回执行.这样,线程在唤醒之前将完全消耗零CPU时间.

如果是Critical Section,则当某个其他线程已经进入同一Critical Section实例时,该线程将被阻塞,而当另一个线程离开该Critical Section实例时,该线程将被唤醒.
对于非常相似的Mutex和许多其他同步对象,还有另一个特殊的唤醒条件:超时.这是区别.具有(带有(可选)或附加的)带有超时参数的阻塞方法的同步对象称为等待".

这就是答案.您唯一的问题是,该术语并不是真正的自我描述,而是有些误导.我个人试图避免这种情况.

—SA
This is some terminology in some documentation I cannot be responsible for.

I just took a look at some object and think I can see the difference. To my taste, it is really minor. There is one simplification which makes Critical Section different. It can be considered as a lightweight version of Mutex. It has a bit simplified interface and can only be used for synchronization between threads of the same process, not between threads of different processes.

First of all, the ''Synchronization Objects'' primitives bring the thread in a special wait state. OS switches out the thread entering the Critical Section or waiting for other Synchronization Objects and doesn''t schedule it back to execution until it is waked up by a certain interrupt condition. In this way the thread consumes strictly zero CPU time until it is awakened.

In case of Critical Section, the thread is blocked when some other thread had already entered the same Critical Section instance and is awakened when the other thread leaves this Critical Section instance.

For the very similar Mutex and many other Synchronization Objects there is another special wake-up condition: a timeout. This is the difference. The Synchronization Objects which have an (optional or additional) blocking method with a timeout parameter are called Waitable.

This is the answer. Your only problem is that this term is not really self-descriptive but somewhat misleading. I personally try to avoid it.

—SA


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

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