package edu.nyu.cs9053.concurrency.semaphore;

import edu.nyu.cs9053.concurrency.Concurrent;

import java.util.concurrent.Callable;
import java.util.concurrent.Semaphore;

/**
 * User: blangel
 * Date: 11/9/14
 * Time: 2:43 PM
 */
public class SemaphoreHavoc {

    public static void main(String[] args) throws Exception {
        final Semaphore binarySemaphore = new Semaphore(1);
        final UniqueNumberGenerator generator = new UniqueNumberGenerator(binarySemaphore);
        Callable<Long> logic = new Callable<Long>() {
            @Override public Long call() throws Exception {
                return generator.next();
            }
        };
        Runnable havoc = new Runnable() {
            @Override public void run() {
                binarySemaphore.release();
            }
        };
        Concurrent.run(logic, 2, havoc);
    }

}
