gpt4 book ai didi

linux - read_lock和write_lock的优点

转载 作者:太空宇宙 更新时间:2023-11-04 10:48:22 28 4
gpt4 key购买 nike

我正在研究 read_lock 和 write_lock。

看来我可以用自旋锁代替读写锁。

所以我想知道使用读写锁有什么好处

当我使用 read_lock 和 write_lock 时,比只使用 spin_lock 有什么优势?

最佳答案

简短的谷歌搜索将这一段翻了过来:

Sometimes, lock usage can be clearly divided into readers and writers. For example, consider a list that is both updated and searched. When the list is updated (written to), it is important that no other threads of execution concurrently write to or read from the list. Writing demands mutual exclusion. On the other hand, when the list is searched (read from), it is only important that nothing else write to the list. Multiple concurrent readers are safe so long as there are no writers. The task list's access patterns (discussed in Chapter 3, "Process Management") fit this description. Not surprisingly, the task list is protected by a reader-writer spin lock.

(来源:link)

所以基本上,使用 read_lock/write_lock 比常规的自旋锁给你更多的权力来拒绝/允许不同的锁用户,这取决于他们的需要,就像上面的例子一样。

关于linux - read_lock和write_lock的优点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32096928/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com