28 lines
386 B
Plaintext
Raw Normal View History

2026-01-21 18:59:54 +08:00
C MP+poonceonces
(*
* Result: Sometimes
*
* Can the counter-intuitive message-passing outcome be prevented with
* no ordering at all?
*)
{}
2026-01-29 22:25:33 +08:00
P0(int *buf, int *flag) // Producer
2026-01-21 18:59:54 +08:00
{
2026-01-29 22:25:33 +08:00
WRITE_ONCE(*buf, 1);
WRITE_ONCE(*flag, 1);
2026-01-21 18:59:54 +08:00
}
2026-01-29 22:25:33 +08:00
P1(int *buf, int *flag) // Consumer
2026-01-21 18:59:54 +08:00
{
int r0;
int r1;
2026-01-29 22:25:33 +08:00
r0 = READ_ONCE(*flag);
r1 = READ_ONCE(*buf);
2026-01-21 18:59:54 +08:00
}
2026-01-29 22:25:33 +08:00
exists (1:r0=1 /\ 1:r1=0) (* Bad outcome. *)