开发者

Is there a function in boost to find how many people are waiting on a mutex lock?

I am using boost 1.4开发者_运维问答1.0. Is there a way to use boost to find how many people are waiting on the lock?


No: there is no way to get a reliable answer as it could change before the function returns, and Boost's interface doesn't provide an unreliable method either.

If you want such a thing, you'll need to implement your own thread-safe counter alongside the mutex; off the top of my head I'm not sure that you could do that reliably either, but you could quite easily distinguish between "approximately none", "a few" and "lots" if that's good enough for your needs.


You could put a mutex around the mutex request that increments a counter and only allows you to access the mutex when that counter is zero.

This seems like terrible overkill, though.

Probably a better way to do this would be to build a small queue and have all requests added to the queue (with a mutex around the push_back and pop_front and an additional peek_front).

This seems a rather interesting exercise to do, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜