Back to home page

OSCL-LXR

 
 

    


0001 C MP+polocks
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
0011  * to see all prior accesses by those other CPUs.
0012  *)
0013 
0014 {}
0015 
0016 P0(int *buf, int *flag, spinlock_t *mylock) // Producer
0017 {
0018         WRITE_ONCE(*buf, 1);
0019         spin_lock(mylock);
0020         WRITE_ONCE(*flag, 1);
0021         spin_unlock(mylock);
0022 }
0023 
0024 P1(int *buf, int *flag, spinlock_t *mylock) // Consumer
0025 {
0026         int r0;
0027         int r1;
0028 
0029         spin_lock(mylock);
0030         r0 = READ_ONCE(*flag);
0031         spin_unlock(mylock);
0032         r1 = READ_ONCE(*buf);
0033 }
0034 
0035 exists (1:r0=1 /\ 1:r1=0) (* Bad outcome. *)