Question: Write code for the following scenario - you can choose to use either an unnamed or a named semaphore. A university has three licenses for

Write code for the following scenario - you can choose to use either an unnamed or a named semaphore. A university has three licenses for a software application. There are seven students in the project group who all need to use the software - because there are three licenses, at most, three students can use the software at a time. In main ( ) create seven threads using a for loop, one for each of the students. Each student (thread) calls the same thread function. In the thread function request a license and check if the software is available. Once a license becomes available, execute for a random period of time between 1 and 5 seconds to simulate using the software, then finally release the license. In main() join all threads using a for loop and print a final message indicating that all students (threads) have finished executing. A sample output is shown below, note that your threads may execute in a different order. \begin{tabular}{l} Student 1 wants to use the software \\ Student 1 has checked out a license... \\ Student 2 wants to use the software \\ Student 2 has checked out a license... \\ Student 3 wants to use the software \\ Student 3 has checked out a license... \\ Student 4 wants to use the software \\ Student 5 wants to use the software \\ Student 6 wants to use the software \\ Student 7 wants to use the software \\ Student 1 has finished using the software and is checking in their license... \\ Student 2 has finished using the software and is checking in their license... \\ Student 3 has finished using the software and is checking in their license... \\ Student 4 has checked out a license... \\ Student 5 has checked out a license... \\ Student 6 has checked out a license... \\ Student 6 has finished using the software and is checking in their license... \\ Student 5 has finished using the software and is checking in their license... \\ Student 7 has checked out a license... \\ Student 4 has finished using the software and is checking in their license... \\ Student 7 has finished using the software and is checking in their license... \\ All students have completed their assignment \\ \hline \end{tabular}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
