162306a36Sopenharmony_ciC MP+porevlocks 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci(* 462306a36Sopenharmony_ci * Result: Never 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * This litmus test demonstrates how lock acquisitions and releases can 762306a36Sopenharmony_ci * stand in for smp_load_acquire() and smp_store_release(), respectively. 862306a36Sopenharmony_ci * In other words, when holding a given lock (or indeed after releasing a 962306a36Sopenharmony_ci * given lock), a CPU is not only guaranteed to see the accesses that other 1062306a36Sopenharmony_ci * CPUs made while previously holding that lock, it is also guaranteed to 1162306a36Sopenharmony_ci * see all prior accesses by those other CPUs. 1262306a36Sopenharmony_ci *) 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci{} 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ciP0(int *buf, int *flag, spinlock_t *mylock) // Consumer 1762306a36Sopenharmony_ci{ 1862306a36Sopenharmony_ci int r0; 1962306a36Sopenharmony_ci int r1; 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci r0 = READ_ONCE(*flag); 2262306a36Sopenharmony_ci spin_lock(mylock); 2362306a36Sopenharmony_ci r1 = READ_ONCE(*buf); 2462306a36Sopenharmony_ci spin_unlock(mylock); 2562306a36Sopenharmony_ci} 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ciP1(int *buf, int *flag, spinlock_t *mylock) // Producer 2862306a36Sopenharmony_ci{ 2962306a36Sopenharmony_ci spin_lock(mylock); 3062306a36Sopenharmony_ci WRITE_ONCE(*buf, 1); 3162306a36Sopenharmony_ci spin_unlock(mylock); 3262306a36Sopenharmony_ci WRITE_ONCE(*flag, 1); 3362306a36Sopenharmony_ci} 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ciexists (0:r0=1 /\ 0:r1=0) (* Bad outcome. *) 36