xref: /linux/tools/memory-model/litmus-tests/MP+onceassign+derefonce.litmus (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
18f32543bSPaul E. McKenneyC MP+onceassign+derefonce
28f32543bSPaul E. McKenney
38f32543bSPaul E. McKenney(*
48f32543bSPaul E. McKenney * Result: Never
58f32543bSPaul E. McKenney *
68f32543bSPaul E. McKenney * This litmus test demonstrates that rcu_assign_pointer() and
78f32543bSPaul E. McKenney * rcu_dereference() suffice to ensure that an RCU reader will not see
88f32543bSPaul E. McKenney * pre-initialization garbage when it traverses an RCU-protected data
98f32543bSPaul E. McKenney * structure containing a newly inserted element.
108f32543bSPaul E. McKenney *)
111c27b644SPaul E. McKenney
121c27b644SPaul E. McKenney{
13*5c587f9bSAkira Yokosawap=y;
141c27b644SPaul E. McKenney}
151c27b644SPaul E. McKenney
16b6ff3084SPaul E. McKenneyP0(int *x, int **p) // Producer
171c27b644SPaul E. McKenney{
181c27b644SPaul E. McKenney	WRITE_ONCE(*x, 1);
19acc4bdc5SPaul E. McKenney	rcu_assign_pointer(*p, x);
201c27b644SPaul E. McKenney}
211c27b644SPaul E. McKenney
22b6ff3084SPaul E. McKenneyP1(int *x, int **p) // Consumer
231c27b644SPaul E. McKenney{
241c27b644SPaul E. McKenney	int *r0;
251c27b644SPaul E. McKenney	int r1;
261c27b644SPaul E. McKenney
271c27b644SPaul E. McKenney	rcu_read_lock();
28acc4bdc5SPaul E. McKenney	r0 = rcu_dereference(*p);
291c27b644SPaul E. McKenney	r1 = READ_ONCE(*r0);
301c27b644SPaul E. McKenney	rcu_read_unlock();
311c27b644SPaul E. McKenney}
321c27b644SPaul E. McKenney
33b6ff3084SPaul E. McKenneyexists (1:r0=x /\ 1:r1=0) (* Bad outcome. *)
34