Consider a scenario where students go to library, students study and students leave the library. There will be 2 students in the library initially and other 3 will be entering the library. The condition is that at any point of time there should be at least 2 students studying in the library.(eg if there are only 2 students left in the library and if 1 student is studying then the other student cannot leave. The last student can only leave once the student who was studying is done studying). You should print the states of the each student whenever they are entering the library, studying or leaving the library and also the total number of students left in the library. Implement this using semaphore.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.