public class Semaphore {
	int count;
	
	public Semaphore (int limit) {
		count = limit;
	}

	synchronized void enter () {
		count--;
		if (count < 0) {
			try {
				wait();
			}
			catch (InterruptedException e) {
				System.out.println("Fatal Error Exiting....");
				System.exit(0);
			}
		}
	}
	
	synchronized void exit () {
		count++;
		if (count <= 0) {
			notify();
		}
	}
}
		
	