/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* Written by Doug Lea with assistance from members of JCP JSR-166
* Expert Group and released to the public domain, as explained at
*/
/*
* @test
* @bug 6445158
* @summary Basic tests for Phaser
* @author Chris Hegarty
*/
public class Basic {
try {
unexpected(ie);
}
}
// t.printStackTrace();
fail("Mismatch in thread " +
a.getName() + ": " +
t + ", " +
} else {
pass();
}
}
//----------------------------------------------------------------
// Mechanism to get all test threads into "running" mode.
//----------------------------------------------------------------
private static void toTheStartingGate() {
try {
boolean expectNextPhase = false;
expectNextPhase = true;
}
pass();
} catch (Throwable t) {
unexpected(t);
// reset(atTheStartingGate);
throw new Error(t);
}
}
//----------------------------------------------------------------
// Convenience methods for creating threads that call arrive,
// awaitAdvance, arriveAndAwaitAdvance, awaitAdvanceInterruptibly
//----------------------------------------------------------------
Arriver() {
this("Arriver");
}
this.setDaemon(true);
}
private volatile int phase;
}
}
}
try {
else
}
final long timeout,
try {
if (timeout < 0)
else
unit));
}
int i = 0;
public boolean hasNext() { return true; }
switch ((i++)&7) {
case 0: case 4:
case 1: case 5:
case 2: case 6: case 7:
default:
public void remove() {throw new UnsupportedOperationException();}};
}
// Returns an infinite lazy list of all possible awaiter only combinations.
int i = 0;
public boolean hasNext() { return true; }
switch ((i++)&7) {
case 1: case 4: case 7:
case 2: case 5:
default:
public void remove() {throw new UnsupportedOperationException();}};
}
//----------------------------------------------------------------
// Normal use
//----------------------------------------------------------------
try {
int phase = 0;
for (int i = 0; i < 10; i++) {
}
} catch (Throwable t) { unexpected(t); }
//----------------------------------------------------------------
// One thread interrupted
//----------------------------------------------------------------
try {
for (int i = 0; i < 4; i++) {
// allow a1 to block in awaitAdvanceInterruptibly
phase++;
}
} catch (Throwable t) { unexpected(t); }
//----------------------------------------------------------------
// Phaser is terminated while threads are waiting
//----------------------------------------------------------------
try {
for (int i = 0; i < 4; i++) {
}
} catch (Throwable t) { unexpected(t); }
//----------------------------------------------------------------
// Adds new unarrived parties to this phaser
//----------------------------------------------------------------
try {
for (int i = 1; i < 5; i++) {
// register 3 more
for (int z=0; z<(3*i); z++) {
}
}
arriverList.clear();
phase++;
}
} catch (Throwable t) { unexpected(t); }
//----------------------------------------------------------------
// One thread timed out
//----------------------------------------------------------------
try {
for (int i = 0; i < 2; i++) {
}
}
} catch (Throwable t) { unexpected(t); }
//----------------------------------------------------------------
// Barrier action completed normally
//----------------------------------------------------------------
try {
if (phase >= 3)
return true; // terminate
return false;
}
};
for (int i = 0; i < 4; i++) {
if (i < 3) {
} else
}
} catch (Throwable t) { unexpected(t); }
}
//--------------------- Infrastructure ---------------------------
else fail(x + " not equal to " + y);}
}