Multithreaded-Concurrency-Operating-Systems-Project / problem2_explanation.txt
problem2_explanation.txt
Raw
The program starts in main by initializing 2 semaphores. One will be used to track and lock data for 
manipulating global data (semaphore) and the other will be to control thread sleeping until that have
 a task to do (nap)
The first 15 planes were automatically designated as large with the last 30 made small. This was done
 by passing the index of the loop that created these threads into the routine said thread would execute.
The routine would cast the argument received back to an int, and threads with ID 14 or less would go 
down a LARGE path, and all other threads went down a SMALL path with a switch case that would give each
 set its own logic to work with
Once threads were split into their size group, they would randomy pick a set of regions to attempt 
takeoff. Each large (3 sections) and small (2 sections) would randomly pick a set of regions using 
rand() then taxi to that region.
again, using a random number between 0 and 1, a plane would choose to go to the highest number or
 lowest numbered section (0 for decreasing and therefore starting at the highest number and 1 for 
 the opposite)
The threads would then check a global array that represents the population of each section (0 for 
empty and 1 for taken), and will ONLY take off on its picked region if all sections are flagged as 
0
if the entirety of a thread's picked section is not available, it will sleep on a different semaphore 
named "nap" that will be unlocked only after a different plane using that section declares it has 
taken off and unlocks the nap semaphore and resets the flags for those sections as 0
After flying away, a plane will wait for a random ammount of time, then return to the airport and 
land. It will then sleep for a random ammount of time before repeating the process.