Back to home page

OSCL-LXR

 
 

    


0001 C MP+porevlocks
0002 
0003 (*
0004  * Result: Never
0005  *
0006  * This litmus test demonstrates how lock acquisitions and releases can
0007  * stand in for smp_load_acquire() and smp_store_release(), respectively.
0008  * In other words, when holding a given lock (or indeed after releasing a
0009  * given lock), a CPU is not only guaranteed to see the accesses that other
0010  * CPUs made while previously holding that lock, it is also guaranteed to
0011  * see all prior accesses by those other CPUs.
0012  *)
0013 
0014 {}
0015 
0016 P0(int *buf, int *flag, spinlock_t *mylock) // Consumer
0017 {
0018         int r0;
0019         int r1;
0020 
0021         r0 = READ_ONCE(*flag);
0022         spin_lock(mylock);
0023         r1 = READ_ONCE(*buf);
0024         spin_unlock(mylock);
0025 }
0026 
0027 P1(int *buf, int *flag, spinlock_t *mylock) // Producer
0028 {
0029         spin_lock(mylock);
0030         WRITE_ONCE(*buf, 1);
0031         spin_unlock(mylock);
0032         WRITE_ONCE(*flag, 1);
0033 }
0034 
0035 exists (0:r0=1 /\ 0:r1=0) (* Bad outcome. *)