36 lines
825 B
Plaintext
Raw Normal View History

2026-01-21 18:59:54 +08:00
C MP+polocks
(*
* Result: Never
*
* This litmus test demonstrates how lock acquisitions and releases can
* stand in for smp_load_acquire() and smp_store_release(), respectively.
* In other words, when holding a given lock (or indeed after releasing a
* given lock), a CPU is not only guaranteed to see the accesses that other
* CPUs made while previously holding that lock, it is also guaranteed
* to see all prior accesses by those other CPUs.
*)
{}
2026-01-29 22:25:33 +08:00
P0(int *buf, int *flag, spinlock_t *mylock) // Producer
2026-01-21 18:59:54 +08:00
{
2026-01-29 22:25:33 +08:00
WRITE_ONCE(*buf, 1);
2026-01-21 18:59:54 +08:00
spin_lock(mylock);
2026-01-29 22:25:33 +08:00
WRITE_ONCE(*flag, 1);
2026-01-21 18:59:54 +08:00
spin_unlock(mylock);
}
2026-01-29 22:25:33 +08:00
P1(int *buf, int *flag, spinlock_t *mylock) // Consumer
2026-01-21 18:59:54 +08:00
{
int r0;
int r1;
spin_lock(mylock);
2026-01-29 22:25:33 +08:00
r0 = READ_ONCE(*flag);
2026-01-21 18:59:54 +08:00
spin_unlock(mylock);
2026-01-29 22:25:33 +08:00
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. *)