I am wondering Why RCU is designed to protect pointer assignment and access. If the rcu_read_lock is used to protect to normal varliable access, what will happen?
Asked
Active
Viewed 123 times
0
-
"If the rcu_read_lock is used to protect to normal varliable access" - By itself, `rcu_read_lock` provides no protection. Several processes/threads could be inside RCU-section at the same time. This opposites to e.g. spinlocks: at most one process/thread could be inside a section, protected by a specific spinlock object. – Tsyvarev Apr 29 '21 at 11:25
-
@Tsyvarev So why does rcu only protect the pointer value itself, but not protect memory access pointed by the pointer. – river Apr 29 '21 at 12:34
-
RCU expects that the memory pointed by a protected pointer is **not changed**. So this memory could be read concurrently by anyone who has a pointer to that memory and holds RCU read lock. RCU approach for update the data is: 1. **Read** existing data. 2. **Copy** these data into some other memory. 3. **Update** (modify) that other memory. 4. Replace pointer to the existed data with a pointer to that other memory. – Tsyvarev Apr 29 '21 at 13:23