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

Code in C

Code in C Write code for the following scenario - you can

choose to use either an unnamed or a named semaphore. A university

Write code for the following scenario - you can choose to use either an unnamed or a named semaphore. A university has three licenses available for a piece of software. There are seven students in the research 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 a license is available. Once a license becomes available, execute for a random period of time between 1 and 5 seconds, 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. 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 completed the assignment and is returning the license... Student 2 has completed the assignment and is returning the license... Student 3 has completed the assignment and is returning the 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 completed the assignment and is returning the license... Student 5 has completed the assignment and is returning the license... Student 7 has checked out a license... Student 4 has completed the assignment and is returning the license... Student 7 has completed the assignment and is returning the license... All students have completed their assignment

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!