- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在研究 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/
为了优化从哈希表中清除项目,我使用了 read_lock 和 write_lock : DEFINE_RWLOCK(ht_rwlock); void Clear(void (*deleter)(con
在 Linux 内核中,读/写自旋锁用于同步访问任务列表。然而,read_(un)lock 用于读取,而 write_(un)lock_irq 用于写入。为什么写锁定时需要关闭中断? 最佳答案 对于曾
我是一名优秀的程序员,十分优秀!