public class Semaphore
{
	int s;
	
	public Semaphore(int s)
	{
		assert(s > 0);
		this.s = s;
	} //constructor
	
	public synchronized void p()
	{
		while (s == 0)
		{
			try
			{
				wait();
			} //try
			catch (InterruptedException ie)
			{
			System.out.println("An InterruptedException caught\n"+ie.getMessage());
			ie.printStackTrace();
			} //catch
		} //while
		s--;
	} //p()
	
	public synchronized void v()
	{
		s++;
		notify();
	} //v()
} //class Semaphore