Skip to content

Commit be4a379

Browse files
joelagnelpaulmckrcu
authored andcommitted
Documentation: LKMM: Add litmus test for RCU GP guarantee where updater frees object
This adds an example for the important RCU grace period guarantee, which shows an RCU reader can never span a grace period. Acked-by: Andrea Parri <[email protected]> Signed-off-by: Joel Fernandes (Google) <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent c1b1460 commit be4a379

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
C RCU+sync+free
2+
3+
(*
4+
* Result: Never
5+
*
6+
* This litmus test demonstrates that an RCU reader can never see a write that
7+
* follows a grace period, if it did not see writes that precede that grace
8+
* period.
9+
*
10+
* This is a typical pattern of RCU usage, where the write before the grace
11+
* period assigns a pointer, and the writes following the grace period destroy
12+
* the object that the pointer used to point to.
13+
*
14+
* This is one implication of the RCU grace-period guarantee, which says (among
15+
* other things) that an RCU read-side critical section cannot span a grace period.
16+
*)
17+
18+
{
19+
int x = 1;
20+
int *y = &x;
21+
int z = 1;
22+
}
23+
24+
P0(int *x, int *z, int **y)
25+
{
26+
int *r0;
27+
int r1;
28+
29+
rcu_read_lock();
30+
r0 = rcu_dereference(*y);
31+
r1 = READ_ONCE(*r0);
32+
rcu_read_unlock();
33+
}
34+
35+
P1(int *x, int *z, int **y)
36+
{
37+
rcu_assign_pointer(*y, z);
38+
synchronize_rcu();
39+
WRITE_ONCE(*x, 0);
40+
}
41+
42+
exists (0:r0=x /\ 0:r1=0)

0 commit comments

Comments
 (0)