如何使用信号量实现条件变量? [英] How can you implement a condition variable using semaphores?

查看:557
本文介绍了如何使用信号量实现条件变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前一段时间,我在考虑如何彼此实现各种同步原语.例如,在pthread中,您可以获得互斥体和条件变量,并从中可以构建信号量.

A while back I was thinking about how to implement various synchronization primitives in terms of one another. For example, in pthreads you get mutexes and condition variables, and from these can build semaphores.

在Windows API(或至少是Windows API的较旧版本)中,有互斥体和信号量,但没有条件变量.我认为应该可以从互斥量和信号量中构建条件变量,但是对于我的一生,我只是想不到这样做的方法.

In the Windows API (or at least, older versions of the Windows API) there are mutexes and semaphores, but no condition variables. I think that it should be possible to build condition variables out of mutexes and semaphores, but for the life of me I just can't think of a way to do so.

有人知道这样做的好构造吗?

Does anyone know of a good construction for doing this?

推荐答案

这是

Here's a paper from Microsoft Research [pdf] which deals with exactly that.

这篇关于如何使用信号量实现条件变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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