rcu_read_lock()¶
Purpose¶
rcu_read_lock() marks the beginning of an RCU read-side critical section.
Code inside this section may safely access RCU-protected objects obtained through rcu_dereference().
Prototype¶
Header¶
Usage Pattern¶
Behavior¶
rcu_read_lock() does not acquire a traditional lock.
It does not provide mutual exclusion.
Instead, it tells the RCU subsystem:
The object must not be reclaimed until the reader exits the read-side critical section.
Important Rules¶
- Always pair with
rcu_read_unlock(). - Keep the read-side critical section short.
- Use
rcu_dereference()to load RCU-protected pointers. - Do not assume it protects data consistency.
- Do not use it as a replacement for a mutex.
Common Mistake¶
Incorrect:
The pointer is loaded without rcu_dereference().
Correct: