/* mutex.c for task synchronization */ #include "mutex.h" #include #include static int n_thread; static pthread_mutex_t *ready; /* [n_thread]; allows worker to proceed */ static pthread_mutex_t *done; /* [n_thread]; allows master to proceed */ static pthread_mutex_t *ack; /* [n_thread]; acknowlege proceeding */ static pthread_t *threads; /* [n_thread]; */ static int debug = 0; void mutex_init(int num_threads) // call only once { n_thread = num_threads; ready = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)*n_thread); done = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)*n_thread); ack = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)*n_thread); threads = (pthread_t *)malloc(sizeof(pthread_t)*n_thread); } /* end mutex_init */ void master_init(void *(*worker_code)(void * threadID)) { int rc, t; for(t=0; t