ArrayCompositeDisposable extends AtomicReferenceArray<Disposable> implements Disposable { @Override public void dispose() { if (get(0) != DisposableHelper.DISPOSED) { int s = length(); for (int i = 0; i < s; i++) { Disposable o = get(i); if (o != DisposableHelper.DISPOSED) { o = getAndSet(i, DisposableHelper.DISPOSED); if (o != DisposableHelper.DISPOSED && o != null) { o.dispose(); } } } } } ArrayCompositeDisposable(int capacity); boolean setResource(int index, Disposable resource); Disposable replaceResource(int index, Disposable resource); @Override void dispose(); @Override boolean isDisposed();  }
@Test public void disposeRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final ArrayCompositeDisposable acd = new ArrayCompositeDisposable(2); Runnable r = new Runnable() { @Override public void run() { acd.dispose(); } }; TestHelper.race(r, r); } }