- 论坛徽章:
- 0
|
呵呵,ShadowStar总结的好!
想想,“类似于一个全局的状态标志”,这样更易理解!
call_rcu的时候,检查 ...
qiangsheng_cu 发表于 2010-06-02 10:11 ![]()
最近刚刚完成一个结合了红黑树和hash表的快速查找模块,用的就是RCU,完全没有用到锁(除了netlink保护用的mutex)。
不过由于职业道德的原因,我无法把代码发布出来。- /**
- * rcu_read_lock - mark the beginning of an RCU read-side critical section.
- *
- * When synchronize_rcu() is invoked on one CPU while other CPUs
- * are within RCU read-side critical sections, then the
- * synchronize_rcu() is guaranteed to block until after all the other
- * CPUs exit their critical sections. Similarly, if call_rcu() is invoked
- * on one CPU while other CPUs are within RCU read-side critical
- * sections, invocation of the corresponding RCU callback is deferred
- * until after the all the other CPUs exit their critical sections.
- *
- * Note, however, that RCU callbacks are permitted to run concurrently
- * with RCU read-side critical sections. One way that this can happen
- * is via the following sequence of events: (1) CPU 0 enters an RCU
- * read-side critical section, (2) CPU 1 invokes call_rcu() to register
- * an RCU callback, (3) CPU 0 exits the RCU read-side critical section,
- 4) CPU 2 enters a RCU read-side critical section, (5) the RCU
- * callback is invoked. This is legal, because the RCU read-side critical
- * section that was running concurrently with the call_rcu() (and which
- * therefore might be referencing something that the corresponding RCU
- * callback would free up) has completed before the corresponding
- * RCU callback is invoked.
- *
- * RCU read-side critical sections may be nested. Any deferred actions
- * will be deferred until the outermost RCU read-side critical section
- * completes.
- *
- * It is illegal to block while in an RCU read-side critical section.
- */
复制代码 上面的是include/linux/rcupdate.h中的说明。
call_rcu确实需要等待所有CPU上的rcu_read_lock都unlock才会调用,也确实会发生您所说的第二种情况。
所以说,RCU是一种延迟调用的处理,不是实时的。
call_rcu确实是在一次上下文切换之后才调用的,我是这么理解的。 |
评分
-
查看全部评分
|