Linda exercise

Due April 10, 2003

 

We want to build a distributed system for our CIS. department.  But coordinating a set of shared resources is a real problem.  So Dr. Saunders asked us to program simple distributed Semaphore in C-Linda.

              The conventional definition of a semaphore is an integer counter that represents the count of available resources at any given time.  A semaphore is controlled by two primary operations:

 

You can think of the semaphore entries as a pool of available resources: If n entries exist in the TupleSpace at a given time, that means n resources are currently unused and available.  That is our TupleSpace-based implementation we are replacing an integer counter.

To implement the distributed semaphone we need to define a DistributedSemaphore with three functions(Create, Down, Up, Destroy) implemented using Linda's tuple space. The Create(char* sem, unsigned int n) creates a semaphore with name sem for controlling n resources. the name sem is used to identify the semaphore in the down and up functions. The int Destroy(char* sem) function removes all tuples in tuplespace which represent the semaphore and returns 0 provided the cleanup succeeds. It should not be called if there are processes blocked on Down calls. It may be that, when Destroy is called, the semaphore is not at the n level specified at the Create call. The Destroy call must NOT become blocked in this situation, but must return with a non-zero value.

 

Note: This is a paper exercise. We do not have a C-Linda preprocessor.  However, C-Linda has only 6 functions.  If you have any problem or any question, please email at tae@udel.edu.