Java Code Examples for java.util.concurrent.atomic.AtomicIntegerArray#weakCompareAndSetPlain()
The following examples show how to use
java.util.concurrent.atomic.AtomicIntegerArray#weakCompareAndSetPlain() .
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: AtomicIntegerArray9Test.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() { AtomicIntegerArray aa = new AtomicIntegerArray(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: AtomicIntegerArray9Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * repeated weakCompareAndSetPlain succeeds in changing value when equal * to expected */ public void testWeakCompareAndSetPlain() { AtomicIntegerArray aa = new AtomicIntegerArray(SIZE); for (int i = 0; i < SIZE; i++) { aa.set(i, 1); do {} while (!aa.weakCompareAndSetPlain(i, 1, 2)); do {} while (!aa.weakCompareAndSetPlain(i, 2, -4)); assertEquals(-4, aa.get(i)); do {} while (!aa.weakCompareAndSetPlain(i, -4, 7)); assertEquals(7, aa.get(i)); } }