public void lock ( ) { Thread t = Thread . currentThread ( ) ; if ( t == owner . get ( ) ) { // if re-enter, increment the count. count ++ ; return ; } while ( owner . compareAndSet ( null , t ) ) { } //spin }
reentrant count of a thread no need to be volatile