[concurrency-interest] Enforcing ordered execution of critical sections?

Hanson Char hanson.char at gmail.com
Sat Dec 13 23:26:00 EST 2014


Hi,

I am looking for a construct that can be used to efficiently enforce
ordered execution of multiple critical sections, each calling from a
different thread. The calling threads may run in parallel and may call
the execution method out of order.  The perceived construct would
therefore be responsible for re-ordering the execution of those
threads, so that their critical sections (and only the critical
section) will be executed in order.

Would something like the following API already exist?

/**
 * Used to enforce ordered execution of critical sections calling from multiple
 * threads, parking and unparking the threads as necessary.
 */
public class OrderedExecutor<T> {
    /**
     * Executes a critical section at most once with the given order, parking
     * and unparking the current thread as necessary so that all critical
     * sections executed by different threads using this executor take place in
     * the order from 1 to n consecutively.
     */
    public T execCriticalSectionInOrder(final int order,
            final Callable<T> criticalSection) throws InterruptedException;
}

Regards,
Hanson


More information about the Concurrency-interest mailing list