Assignment 6: Threads in C

Redo assignment #1 in C. Recall that a Java solution for Assignment #1 was posted on the moddle page. You will need to redo the semaphor class, with the following changes:

  1. Add a new type pthread_sem_t, with associated routines pthread_sem_init, pthread_sem_destroy, pthread_sem_acquire, and pthread_sum_release.
  2. Create a header file pthread_sem.h with the appropriate signatures, and an implementation file pthread_sem.c.
  3. Modify the implementation of the semaphor as follows: rather than storing a list containing all threads that have a pending acquire, you should store a list/collection containing all threads that have at least one pending acquire, and the count of how many pending acquires they have. (This will allow the semaphor to be used in multiple places, including recursive calls). The call to release will decrement the count for that thread, and if the count goes to zero, that thread is removed from the list/collection. In Java you would do this using a Map<Thread,Integer>, but in C you will have to write your own map.
  4. The release routine returns EPERM if there is an error, and 0 otherwise.