1*7e7eb5aeSPaul E. McKenneyC DCL-broken 2*7e7eb5aeSPaul E. McKenney 3*7e7eb5aeSPaul E. McKenney(* 4*7e7eb5aeSPaul E. McKenney * Result: Sometimes 5*7e7eb5aeSPaul E. McKenney * 6*7e7eb5aeSPaul E. McKenney * This litmus test demonstrates more than just locking is required to 7*7e7eb5aeSPaul E. McKenney * correctly implement double-checked locking. 8*7e7eb5aeSPaul E. McKenney *) 9*7e7eb5aeSPaul E. McKenney 10*7e7eb5aeSPaul E. McKenney{ 11*7e7eb5aeSPaul E. McKenney int flag; 12*7e7eb5aeSPaul E. McKenney int data; 13*7e7eb5aeSPaul E. McKenney} 14*7e7eb5aeSPaul E. McKenney 15*7e7eb5aeSPaul E. McKenneyP0(int *flag, int *data, spinlock_t *lck) 16*7e7eb5aeSPaul E. McKenney{ 17*7e7eb5aeSPaul E. McKenney int r0; 18*7e7eb5aeSPaul E. McKenney int r1; 19*7e7eb5aeSPaul E. McKenney int r2; 20*7e7eb5aeSPaul E. McKenney 21*7e7eb5aeSPaul E. McKenney r0 = READ_ONCE(*flag); 22*7e7eb5aeSPaul E. McKenney if (r0 == 0) { 23*7e7eb5aeSPaul E. McKenney spin_lock(lck); 24*7e7eb5aeSPaul E. McKenney r1 = READ_ONCE(*flag); 25*7e7eb5aeSPaul E. McKenney if (r1 == 0) { 26*7e7eb5aeSPaul E. McKenney WRITE_ONCE(*data, 1); 27*7e7eb5aeSPaul E. McKenney WRITE_ONCE(*flag, 1); 28*7e7eb5aeSPaul E. McKenney } 29*7e7eb5aeSPaul E. McKenney spin_unlock(lck); 30*7e7eb5aeSPaul E. McKenney } 31*7e7eb5aeSPaul E. McKenney r2 = READ_ONCE(*data); 32*7e7eb5aeSPaul E. McKenney} 33*7e7eb5aeSPaul E. McKenney 34*7e7eb5aeSPaul E. McKenneyP1(int *flag, int *data, spinlock_t *lck) 35*7e7eb5aeSPaul E. McKenney{ 36*7e7eb5aeSPaul E. McKenney int r0; 37*7e7eb5aeSPaul E. McKenney int r1; 38*7e7eb5aeSPaul E. McKenney int r2; 39*7e7eb5aeSPaul E. McKenney 40*7e7eb5aeSPaul E. McKenney r0 = READ_ONCE(*flag); 41*7e7eb5aeSPaul E. McKenney if (r0 == 0) { 42*7e7eb5aeSPaul E. McKenney spin_lock(lck); 43*7e7eb5aeSPaul E. McKenney r1 = READ_ONCE(*flag); 44*7e7eb5aeSPaul E. McKenney if (r1 == 0) { 45*7e7eb5aeSPaul E. McKenney WRITE_ONCE(*data, 1); 46*7e7eb5aeSPaul E. McKenney WRITE_ONCE(*flag, 1); 47*7e7eb5aeSPaul E. McKenney } 48*7e7eb5aeSPaul E. McKenney spin_unlock(lck); 49*7e7eb5aeSPaul E. McKenney } 50*7e7eb5aeSPaul E. McKenney r2 = READ_ONCE(*data); 51*7e7eb5aeSPaul E. McKenney} 52*7e7eb5aeSPaul E. McKenney 53*7e7eb5aeSPaul E. McKenneylocations [flag;data;0:r0;0:r1;1:r0;1:r1] 54*7e7eb5aeSPaul E. McKenneyexists (0:r2=0 \/ 1:r2=0) 55