如何使windows slim读写锁公平? [英] How to make windows slim read writer lock fair?

查看:176
本文介绍了如何使windows slim读写锁公平?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现windows实现了一个slim reader-writer-lock(见 https://msdn.microsoft.com/en-us/library/windows/desktop/aa904937%28v=vs.85%29.aspx )。不幸的是(对我来说)这个rw-lock既不是fifo也不是公平的(在任何意义上)。
是否有可能使窗口rw锁与一些解决公平或fifo?

解决方案


p>这个rw-lock既不是fifo也不是公平的


我不会指望任何与线程相关的是 或fifo,除非它表示明确。在这种情况下,我希望写锁优先,因为它可能永远不能获得锁如果有很多读取线程,但然后我也不会假设是这样的情况,我没有读

就像你的问题是你对锁有很多争论,引起写线程;因为否则你的读者总是能够共享锁。你应该考虑你的写线程为什么试图持有这么长的锁;缓冲增加例如将有助于缓解这种情况。


i found out that windows implemented a slim reader-writer-lock (see https://msdn.microsoft.com/en-us/library/windows/desktop/aa904937%28v=vs.85%29.aspx ). Unfortunately (for me) this rw-lock is neither fifo nor is it fair (in any sense). Is there a possibility to make the windows rw-lock with some workaround fair or fifo? If not, in which scenarios would you use the windows slim rw-lock?

解决方案

this rw-lock is neither fifo nor is it fair

I wouldn't expect anything to do with threading to be "fair" or "fifo" unless it said it was explicitly. In this case, I would expect writing locks to take priority, as it might never be able to obtain a lock if there are a lot of reading threads, but then I also wouldn't assume that's the case, and I've not read the MS documentation for a better understanding.

That said, it sounds like your issue is that you have a lot of contention on the lock, caused by write threads; because otherwise your readers would always be able to share the lock. You should probably examine why your writing thread(s) are trying to hold the lock for so long; buffering up adds for example will help mitigate this.

这篇关于如何使windows slim读写锁公平?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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