Brooklyn/tools/memory-model/litmus-tests/MP+onceassign+derefonce.litmus

34 lines
593 B
Plaintext
Raw Normal View History

2021-05-27 00:09:36 +05:00
C MP+onceassign+derefonce
(*
* Result: Never
*
* This litmus test demonstrates that rcu_assign_pointer() and
* rcu_dereference() suffice to ensure that an RCU reader will not see
* pre-initialization garbage when it traverses an RCU-protected data
* structure containing a newly inserted element.
*)
{
2021-10-02 21:09:28 +05:00
p=y;
2021-05-27 00:09:36 +05:00
}
2021-10-02 21:09:28 +05:00
P0(int *x, int **p) // Producer
2021-05-27 00:09:36 +05:00
{
WRITE_ONCE(*x, 1);
2021-10-02 21:09:28 +05:00
rcu_assign_pointer(*p, x);
2021-05-27 00:09:36 +05:00
}
2021-10-02 21:09:28 +05:00
P1(int *x, int **p) // Consumer
2021-05-27 00:09:36 +05:00
{
int *r0;
int r1;
rcu_read_lock();
2021-10-02 21:09:28 +05:00
r0 = rcu_dereference(*p);
2021-05-27 00:09:36 +05:00
r1 = READ_ONCE(*r0);
rcu_read_unlock();
}
2021-10-02 21:09:28 +05:00
exists (1:r0=x /\ 1:r1=0) (* Bad outcome. *)