/************************************************************ File: gsemaphore.cc Description: A program that simulates a dependancy graph for a set of threads. The functions for manipulating a general semaphore. Author: Dana Vrajitoru Organization: IUSB Date: November 24, 2004 **************************************************************/ #include "gsemaphore.h" // Assigns the value of the second parameter to the internal semaphore // value and initializes the mutex. void Init_sem(Gsemaphore &sem, int val) { sem.value = val; pthread_mutex_init(&(sem.mutex), NULL); } // Waits until the value has become 0, then increments it. It's a // blocking function. void Test_and_inc(Gsemaphore &sem) { // To be implemented by the student. } // Decreases the value of the semaphore without testing it. It still // must protect the value as a critical section. void Dec(Gsemaphore &sem) { pthread_mutex_lock(&(sem.mutex)); sem.value--; pthread_mutex_unlock(&(sem.mutex)); }