public void clear(int position) {
        int segmentPosition = position >>> log2SegmentSize; /// which segment -- div by num bits per segment
        int longPosition = (position >>> 6) & segmentMask; /// which long in the segment -- remainder of div by num bits per segment
        int bitPosition = position & 0x3F; /// which bit in the long -- remainder of div by num bits in long (64)

        AtomicLongArray segment = getSegment(segmentPosition);

        long mask = ~(1L << bitPosition);

        // Thread safety: we need to loop until we win the race to set the long value.
        while(true) {
            // determine what the new long value will be after we set the appropriate bit.
            long currentLongValue = segment.get(longPosition);
            long newLongValue = currentLongValue & mask;

            // if no other thread has modified the value since we read it, we won the race and we are done.
            if(segment.compareAndSet(longPosition, currentLongValue, newLongValue))
                break;
        }
    }
@Test
    public void testClear() {
        ThreadSafeBitSet set1 = new ThreadSafeBitSet();

        set1.set(10);
        set1.set(20);
        set1.set(21);
        set1.set(22);

        set1.clear(21);

        Assert.assertEquals(3, set1.cardinality());
    }