Multithreaded-Concurrency-Operating-Systems-Project / problem1_explanation.txt
problem1_explanation.txt
Raw
The program has one main mutex which controls access to global vars for all threads.
Then we have 3 main condition variables, one for each sport. One to wake up the people playing the sports
and one to wake up the people queuing for the sports. The last one is to wake up the soccer player leads
who can be invited to join an exsiting game of soccer. 

Our approach is to have two main functions, try_to_queue() and try_to_leave(). These functions are called
by the threads when they want to queue for a sport or leave the feild. The functions will first check if
there are enough people to play their sport, if not they will queue. If there are enough people to play
their sport, they will try to play. If they can't play since a game is going on, the leader (the nth player, 
if the sport requies n players) will queue in a line for when the game is over. Try to leave simply allows the players to leave by decrementing a counter. If the counter reaches 0, they
will wake up the leaders that are ready to start another sport.

The mutex is held by one thread for almost the entire time. The only time it is released is when the thread
is waiting on a condition variable or when they are sleeping.

Currently, we have each player playing the sport twice before they stop exsisting. This can be changed in the main function.