/************************************************************ File: main.cc Description: A program that simulates a dependancy graph for a set of threads. Author: Dana Vrajitoru Organization: IUSB Date: November 24, 2004 **************************************************************/ #include #include using namespace std; #include #include "gsemaphore.h" #include "graph.h" Graph gr; Gsemaphore *sem; // Prototypes. void Create_threads(pthread_t *threads, int nr_threads); void Synchronise(pthread_t *threads, int nr_threads); void *Thread(void *arg); void Task(int id); void Signal_out(int id); int main() { int i, nr_threads; char filename[80]; cout << "Enter the graph filename" << endl; cin>> filename; gr.Read(filename); gr.Print(); nr_threads = gr.nr_vertices; pthread_t *threads = new pthread_t[nr_threads]; sem = new Gsemaphore[nr_threads]; Create_threads(threads, nr_threads); Synchronise(threads, nr_threads); } // Creates the threads calling the producer function, then those // calling the consumer function, and to each of them it passes the // pointer to the number of items as the argument. void Create_threads(pthread_t *threads, int nr_threads) { for (int i=0; i