// Path: src/main/java/org/pcj/internal/InternalFuture.java
// public abstract class InternalFuture<T> {
// 
//     private final Object lock;
//     private boolean signaled;
// 
//     protected InternalFuture() {
//         this.lock = new Object();
//         this.signaled = false;
//     }
// 
//     final protected boolean isSignaled() {
//         synchronized (lock) {
//             return signaled;
//         }
//     }
// 
//     final protected void signal() {
//         synchronized (lock) {
//             signaled = true;
//             lock.notifyAll();
//         }
//     }
// 
//     final protected void await() throws InterruptedException {
//         synchronized (lock) {
//             while (!signaled) {
//                 lock.wait();
//             }
//         }
//     }
// 
//     final protected void await(long timeout, TimeUnit unit) throws TimeoutException, InterruptedException {
//         long nanosTimeout = unit.toNanos(timeout);
//         final long deadline = System.nanoTime() + nanosTimeout;
// 
//         synchronized (lock) {
//             while (!signaled) {
//                 if (nanosTimeout <= 0L) {
//                     throw new TimeoutException("Not done yet.");
//                 }
//                 lock.wait(nanosTimeout / 1_000_000, (int) (nanosTimeout % 1_000_000));
//                 nanosTimeout = deadline - System.nanoTime();
//             }
//         }
//     }
// }


import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.pcj.PcjFuture;
import org.pcj.PcjRuntimeException;
import org.pcj.internal.InternalFuture;
/*
 * Copyright (c) 2011-2021, PCJ Library, Marek Nowicki
 * All rights reserved.
 *
 * Licensed under New BSD License (3-clause license).
 *
 * See the file "LICENSE" for the full license governing this code.
 */
package org.pcj.internal.message.scatter;


/**
 * @author Marek Nowicki (faramir@mat.umk.pl)
 */
public class ScatterFuture extends InternalFuture<Void> implements PcjFuture<Void> {

    private PcjRuntimeException exception;

    ScatterFuture() {
    }

    @Override
    public boolean isDone() {
        return super.isSignaled();
    }

    protected void signalDone() {
        super.signal();
    }

    protected void signalException(PcjRuntimeException exception) {
        this.exception = exception;
        super.signal();
    }

    @Override
    public Void get() throws PcjRuntimeException {
        try {
            super.await();
        } catch (InterruptedException ex) {
            throw new PcjRuntimeException(ex);
        }
// Path: src/main/java/org/pcj/internal/InternalFuture.java
// public abstract class InternalFuture<T> {
// 
//     private final Object lock;
//     private boolean signaled;
// 
//     protected InternalFuture() {
//         this.lock = new Object();
//         this.signaled = false;
//     }
// 
//     final protected boolean isSignaled() {
//         synchronized (lock) {
//             return signaled;
//         }
//     }
// 
//     final protected void signal() {
//         synchronized (lock) {
//             signaled = true;
//             lock.notifyAll();
//         }
//     }
// 
//     final protected void await() throws InterruptedException {
//         synchronized (lock) {
//             while (!signaled) {
//                 lock.wait();
//             }
//         }
//     }
// 
//     final protected void await(long timeout, TimeUnit unit) throws TimeoutException, InterruptedException {
//         long nanosTimeout = unit.toNanos(timeout);
//         final long deadline = System.nanoTime() + nanosTimeout;
// 
//         synchronized (lock) {
//             while (!signaled) {
//                 if (nanosTimeout <= 0L) {
//                     throw new TimeoutException("Not done yet.");
//                 }
//                 lock.wait(nanosTimeout / 1_000_000, (int) (nanosTimeout % 1_000_000));
//                 nanosTimeout = deadline - System.nanoTime();
//             }
//         }
//     }
// }


// Path: src/main/java/org/pcj/internal/message/scatter/ScatterFuture.java
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.pcj.PcjFuture;
import org.pcj.PcjRuntimeException;
import org.pcj.internal.InternalFuture;

/*
 * Copyright (c) 2011-2021, PCJ Library, Marek Nowicki
 * All rights reserved.
 *
 * Licensed under New BSD License (3-clause license).
 *
 * See the file "LICENSE" for the full license governing this code.
 */
package org.pcj.internal.message.scatter;


/**
 * @author Marek Nowicki (faramir@mat.umk.pl)
 */
public class ScatterFuture extends InternalFuture<Void> implements PcjFuture<Void> {

    private PcjRuntimeException exception;

    ScatterFuture() {
    }

    @Override
    public boolean isDone() {
        return super.isSignaled();
    }

    protected void signalDone() {
        super.signal();
    }

    protected void signalException(PcjRuntimeException exception) {
        this.exception = exception;
        super.signal();
    }

    @Override
    public Void get() throws PcjRuntimeException {
        try {
            super.await();
        } catch (InterruptedException ex) {
            throw new PcjRuntimeException(ex);
        }
        if (exception != null) {