如何检查是否有任何等待条件变量的线程? [英] How to check is any thread waiting on condition variable?

查看:162
本文介绍了如何检查是否有任何等待条件变量的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有条件变量名为cond。

I have Condition variable named cond.

如果有任何线程等待cond,是否有任何方法可以给我真或假?

Is there any method which could give me true or false if there is any thread awaiting on cond?

我需要类似的东西:
布尔条件cond.isAwaitingSetEmpty()

I need something like: Boolean cond.isAwaitingSetEmpty()

感谢您的帮助

推荐答案

如果条件是指由 ReentrantLock创建的条件。 newCondition(),然后你可以使用 ReentrantLock.hasWaiters(条件cond)

If by "condition" you mean a Condition created by ReentrantLock.newCondition(), then you can use ReentrantLock.hasWaiters(Condition cond).

这篇关于如何检查是否有任何等待条件变量的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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