G52CON: Exercise 4, Java

A semaphore s is an integer variable which can take only non-negative values. Once it has been given its initial value, the only permissible operations on s are the atomic actions:

A general semaphore can have any non-negative value; a binary semaphore is one whose value is always 0 or 1.

(a) Using the skeleton below, give a definition of a Java class GeneralSemaphore that implements a general semaphore. The class should have two methods P() and V() that implement the corresponding semaphore operations.


class GeneralSemaphore {
    private long resource;

    public GeneralSemaphore (long r) {
        resource = r;
    }

    // method to implement the P operation

    // method to implement the V operation
}


Copyright © 2014 Brian Logan

This file is maintained by Brian Logan
Last modified: 12-Mar-2014, 13:54