查找在POSIX信号量上阻塞的任务数 [英] Find number of tasks blocking on a POSIX semaphore

查看:105
本文介绍了查找在POSIX信号量上阻塞的任务数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过某种方式知道在特定信号量上等待的进程或线程的数量? 就像一个API来检查值. Sem_getvalue()仅返回0,而不是一个负数,其绝对值是某些站点上提到的信号量上阻止的任务数.

Is there any way by which I can know the number of processes or threads waiting on a particular semaphore? Like a API to check the value. Sem_getvalue() only returns 0 and not a negative number whose absolute value is the number of tasks blocking on the semaphore as mentioned on a few sites.

任何帮助都会很棒.

提前谢谢!

推荐答案

也许您可以在调用 sem_wait 之前减小全局 atomic_t 变量并将其递增遇到信号量的话.

May be you could have taken a global atomic_t variable and incremented it before calling sem_wait and decremented in case you get the semaphore.

这篇关于查找在POSIX信号量上阻塞的任务数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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