Java Code Examples for java.util.concurrent.atomic.AtomicLongArray#weakCompareAndSetVolatile()
The following examples show how to use
java.util.concurrent.atomic.AtomicLongArray#weakCompareAndSetVolatile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtomicLongArray9Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * get and set for out of bound indices throw IndexOutOfBoundsException */ public void testIndexing() { AtomicLongArray aa = new AtomicLongArray(SIZE); for (int index : new int[] { -1, SIZE }) { final int j = index; final Runnable[] tasks = { () -> aa.getPlain(j), () -> aa.getOpaque(j), () -> aa.getAcquire(j), () -> aa.setPlain(j, 1), () -> aa.setOpaque(j, 1), () -> aa.setRelease(j, 1), () -> aa.compareAndExchange(j, 1, 2), () -> aa.compareAndExchangeAcquire(j, 1, 2), () -> aa.compareAndExchangeRelease(j, 1, 2), () -> aa.weakCompareAndSetPlain(j, 1, 2), () -> aa.weakCompareAndSetVolatile(j, 1, 2), () -> aa.weakCompareAndSetAcquire(j, 1, 2), () -> aa.weakCompareAndSetRelease(j, 1, 2), }; assertThrows(IndexOutOfBoundsException.class, tasks); } }
Example 2
Source File: AtomicLongArray9Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * repeated weakCompareAndSetVolatile succeeds in changing value when equal * to expected */ public void testWeakCompareAndSetVolatile() { AtomicLongArray aa = new AtomicLongArray(SIZE); for (int i = 0; i < SIZE; i++) { aa.set(i, 1); do {} while (!aa.weakCompareAndSetVolatile(i, 1, 2)); do {} while (!aa.weakCompareAndSetVolatile(i, 2, -4)); assertEquals(-4, aa.get(i)); do {} while (!aa.weakCompareAndSetVolatile(i, -4, 7)); assertEquals(7, aa.get(i)); } }