public class Semaphore
{
    private int count;
	
    public Semaphore (int initCount)
    {
        assert initCount >= 0 : "Precondition: Initial value of count nonnegative";
        count = initCount;
    }
	
    public synchronized void await () throws InterruptedException
    {
        --count;
        if (count < 0)      //  06-01-05: if replaces while
                            // Thanks to Tobias Eger for pointing out the fault.
        {
            try
            {
                wait();
            }
            catch(InterruptedException e)
            {
                throw new InterruptedException("await wait interrupted");
            }
        }
    }
	
    public synchronized void signalize ()
    {
        ++count;
        if (count <= 0)
        {
            notify();
        }
    }
}