by haberman · 11y ago · 0 comments
I don't think that works unfortunately. The thread could be rescheduled on a different CPU in the middle of the read-side critical section. When the critical section is exited, it will decrement a different counter. Scan() will wait until every counter is zero, but this will never happen unless another critical section is also rescheduled in the reverse order.
CPU1 CPU2
---- ----
T1 rcu_read_lock (+1)
read counter (0)
T2 rcu_read_lock (+1)
T2 rcu_read_unlock (-1)
read counter (0)
We'll find that zero is the sum of all counters, even though T1 is still in its read lock.If there were a nice way to swap out the counters then summing would work, unfortunately that introduces an even bigger race :-(
Thanks for the correction!