2021-05-27 00:09:36 +05:00
|
|
|
C MP+poonceonces
|
|
|
|
|
|
|
|
(*
|
|
|
|
* Result: Sometimes
|
|
|
|
*
|
|
|
|
* Can the counter-intuitive message-passing outcome be prevented with
|
|
|
|
* no ordering at all?
|
|
|
|
*)
|
|
|
|
|
|
|
|
{}
|
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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. *)
|