luke
luke

Reputation: 410

Difference between Read-Copy-Update and Reader-Writer-Lock?

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 ?

Upvotes: 5

Views: 3226

Answers (2)

Karthik Balaguru
Karthik Balaguru

Reputation: 7842

In simple terms,

RCU - Concurrency is allowed between a single writer and multiple readers

Reader-Writer locks - Concurrent reads are allowed however not the write operation

Upvotes: 1

askb
askb

Reputation: 6768

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

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

  2. 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: 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.

hope this helps!

Upvotes: 9

Related Questions