2021-05-27 00:09:36 +05:00
|
|
|
C MP+fencewmbonceonce+fencermbonceonce
|
|
|
|
|
|
|
|
(*
|
|
|
|
* Result: Never
|
|
|
|
*
|
|
|
|
* This litmus test demonstrates that smp_wmb() and smp_rmb() provide
|
|
|
|
* sufficient ordering for the message-passing pattern. However, it
|
|
|
|
* is usually better to use smp_store_release() and smp_load_acquire().
|
|
|
|
*)
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
2021-10-02 21:09:28 +05:00
|
|
|
P0(int *buf, int *flag) // Producer
|
2021-05-27 00:09:36 +05:00
|
|
|
{
|
2021-10-02 21:09:28 +05:00
|
|
|
WRITE_ONCE(*buf, 1);
|
2021-05-27 00:09:36 +05:00
|
|
|
smp_wmb();
|
2021-10-02 21:09:28 +05:00
|
|
|
WRITE_ONCE(*flag, 1);
|
2021-05-27 00:09:36 +05:00
|
|
|
}
|
|
|
|
|
2021-10-02 21:09:28 +05:00
|
|
|
P1(int *buf, int *flag) // Consumer
|
2021-05-27 00:09:36 +05:00
|
|
|
{
|
|
|
|
int r0;
|
|
|
|
int r1;
|
|
|
|
|
2021-10-02 21:09:28 +05:00
|
|
|
r0 = READ_ONCE(*flag);
|
2021-05-27 00:09:36 +05:00
|
|
|
smp_rmb();
|
2021-10-02 21:09:28 +05:00
|
|
|
r1 = READ_ONCE(*buf);
|
2021-05-27 00:09:36 +05:00
|
|
|
}
|
|
|
|
|
2021-10-02 21:09:28 +05:00
|
|
|
exists (1:r0=1 /\ 1:r1=0) (* Bad outcome. *)
|