MP+polocks.litmus 825 B

1234567891011121314151617181920212223242526272829303132333435
  1. C MP+polocks
  2. (*
  3. * Result: Never
  4. *
  5. * This litmus test demonstrates how lock acquisitions and releases can
  6. * stand in for smp_load_acquire() and smp_store_release(), respectively.
  7. * In other words, when holding a given lock (or indeed after releasing a
  8. * given lock), a CPU is not only guaranteed to see the accesses that other
  9. * CPUs made while previously holding that lock, it is also guaranteed
  10. * to see all prior accesses by those other CPUs.
  11. *)
  12. {}
  13. P0(int *buf, int *flag, spinlock_t *mylock) // Producer
  14. {
  15. WRITE_ONCE(*buf, 1);
  16. spin_lock(mylock);
  17. WRITE_ONCE(*flag, 1);
  18. spin_unlock(mylock);
  19. }
  20. P1(int *buf, int *flag, spinlock_t *mylock) // Consumer
  21. {
  22. int r0;
  23. int r1;
  24. spin_lock(mylock);
  25. r0 = READ_ONCE(*flag);
  26. spin_unlock(mylock);
  27. r1 = READ_ONCE(*buf);
  28. }
  29. exists (1:r0=1 /\ 1:r1=0) (* Bad outcome. *)