Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 926
luke Avatar asked Feb 12 '23 14:02

luke


2 Answers

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!

like image 167
askb Avatar answered Mar 05 '23 18:03

askb


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

like image 30
Karthik Balaguru Avatar answered Mar 05 '23 19:03

Karthik Balaguru