public boolean set ( int index ) { int wordNum = index >> 6 ; // div 64 int bit = index & 0x3f ; // mod 64 long bitmask = 1L << bit ; long word , oword ; do { word = bits . get ( wordNum ) ; // if set another thread stole the lock if ( ( word & bitmask ) != 0 ) { return false ; } oword = word ; word |= bitmask ; } while ( ! bits . compareAndSet ( wordNum , oword , word ) ) ; return true ; }
Thread safe set operation that will set the bit if and only if the bit was not previously set .