1

Hi,

I am new to rcu locking mechanism in linux kernel.

While trying to understand how rcu works and the provided APIs, I see that rcu_read_lock(), rcu_synchronize() does not take any lock instance. So, lets say I have n independent lists which I want to protect using RCU, are the reads and synchronise() guaranteed to work as they should be?

Pardon me if the question seem too naive

Thanks in advance.

CodeQ
  • 319
  • 1
  • 3
  • 13

1 Answers1

1

Not relying on a mutex is one of the primary benefits of using RCU (read, copy, update). Each rcu_read_lock() will ensure that the data being read locally isn't modified until its rcu_read_unlock() is executed. The synchronize_rcu() will block on all the preceding readers to synchronize the data structure.

Jason
  • 3,777
  • 14
  • 27
  • to get more clarity, how does `synchronize_rcu()` wait for specific `rcu_read_unlock()` to be executed before it can unblock and proceed? – CodeQ Mar 17 '14 at 19:11
  • I'm not entirely familiar with the linux kernel's implementation, but `synchronize_rcu()` only needs to know which `rcu_read_lock()` calls haven't had a matching `rcu_read_unlock()` executed *yet*. Conceptually, it's an equation for pending ops `rcu_read_lock()` = +1, and `rcu_read_unlock()` = -1. My guess is that the value is somehow scoped to the executing thread or cpu. – Jason Mar 17 '14 at 19:41