A viewing platform has seating space for at most 100 people at any one time. People are only admitted when the platform is open and the number of persons does not exceed the prescribed limit. A person once admitted must find an unoccupied seat. Two persons may not share the same seat.
Using condition variables write a class that could be used to control access to the platform and that manages seat allocation so as to maximize concurrent activity.
By creating multiple threads to represent people accessing the platform write a simulator for your control.
Write a class called QueueManager that manages two integer lists. One of its public methods is the function atomicSwap that exchanges two values in the lists. This method takes two index values, one for each list, and exchanges the values. Should either index be out of bounds it should throw an exception. In the event that either list is empty it should also throw the same exception. The swap must appear to occur atomically an external thread should not be able to observe that an item has been removed from one list but not inserted onto the other one. In addition, the implementation must be concurrent it must allow multiple swaps to happen in parallel. Finally, the system should never deadlock. You should write a program to test your solution.
In the ResourceAllocator class described in the lectures client requests are satisfied in first-come-first-served order. In some situations this is not the fairest way to allocate resources because clients with large requests can hold up unnecessarily clients with small requests. One solution is to allow clients with small requests to proceed within certain limits. This is called the bounded overtaking solution because it puts a limit on the number of times clients with large requests may be passed over. Your task is to write a resource manager that sets a limit on the number of times a client may be passed over before receiving their requested resources. Each client has an overtaken count and when this reaches its limit this client must be served next. (See Example 7 in the chapter on Semaphores, Latches and Barriers of your textbook for a discussion of the ResourceAllocator class.)