读写复制更新和读写器锁定之间的区别? [英] Difference between Read-Copy-Update and Reader-Writer-Lock?

查看:124
本文介绍了读写复制更新和读写器锁定之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从编程角度看,它们对我来说几乎一样.根据我在更新数据时所读取的内容,RCU需要维护一个旧副本,直到完成所有读取器为止,这会产生大量开销.

They look pretty much same to me from programming perspective. From what I read when updating the data, RCU needs to maintain an old copy until all readers are done, which creates large overhead.

这是实现方面的唯一区别吗?

Is that the only difference when it comes to implementation ?

推荐答案

读写复制(RCU):与读写器锁不同,以下是我可以考虑的一些要点:

Read-Copy-Update (RCU): is not same as reader-writer lock, here are some of the points I can think off:

  1. 分离更新和回收信息,读者和编写者都可以避免完全锁定.

  1. Separates update and reclamation information, where both readers and writers could avoid locking altogether.

从实现的角度来看,RCU适用于动态分配的数据结构,例如链表,因为编写器不会就地修改数据,而是分配了一个新元素,并使用更新后的内容进行初始化数据.使用原子指针将旧元素替换为新元素,然后新读者将看到新更新的数据.缺点是旧的阅读器仍然会看到数据的旧副本.必须跟踪旧副本,并且读者必须通知RCU基础结构读取已完成,以便可以回收旧数据.

From implementation point of view, RCU is suitable for dynamically allocated data structures, such as linked lists, as the writer does not modify the data in-place, but instead allocates a new element which it initializes with the updated data. The old element is replaced with the new element using an atomic pointer and then new readers will see the newly updated data. Drawback is that old reader will still see the old copy of the data. The old copy must be tracked, and readers must notify the RCU infrastructure that the read is complete, so old data can be reclaimed.

Read-writer-lock:读-写者锁:在这里,写者阻止了另一个读者或另一个写者获得了该锁,尽管它已经获取了该锁.前提是没有写入者拥有多个锁,那么多个读取器可以同时获取一个锁.

Read-writer-lock: Here a writer prevents another reader or another writer from acquiring the lock, while it has aquired the lock already. Multiple readers can acquire a lock simultaneous, provided no writer has taken the lock.

希望这会有所帮助!

这篇关于读写复制更新和读写器锁定之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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