/*************************************************************** File: red_barrier.h Description: A program that implements a barrier using a conditional variable from the pthread library. Author: Dana Vrajitoru Organization: IUSB, Computer and Information Sciences Date: September 2020 ****************************************************************/ #ifndef RED_BARRIER_H #define RED_BARRIER_H // Creates the threads calling the Ship_check_in function. void Create_threads(pthread_t *threads, int no_threads); // Joins all of the threads so that the program doesn;t end before // they have finished the work. void Synchronise(pthread_t *threads, int no_threads); // Inputs the number of ships and initializes the global variables. void Init_data(int &no_threads); // A barrier function based on the number of threads implemented using // a conditional variable. It uses a global counter intialized as // 0. Each thread coming in increments the counter. If the count is // not equal to the number of threads, it goes into a wait on the // conditional variable. The thread that finds the counter equal to // the number of threads broadcasts the condition that releases all of // them. void Barrier(int no_threads) ; // The thread function: gets an id number, prints a message, calls the // barrier, prints a second message. The purpose is to see if the // messages printed by all the threads before the barrier are // separated from the one printed by the threads after the barrier. void *Ship_check_in(void *arg) ; // Copies the value of a global id into the reference parameter and // increments the global id. void Get_id(int &id); // Waits for a given delay specified in miliseconds. void Wait(int miliseconds); #endif