Objective: When dealing with threads and the need to access multiple mutex-prot

Objective:
When dealing with threads and the need to access multiple mutex-protected resources, there is the possibility for “deadlock” to occur. Deadlock (sometimes called “deadly embrace”) is a situation where two or more competing actions are waiting for the other to finish, and thus neither ever does. To illustrate this, we are going to write code to run a drinking game.
Outcomes:
Upon completion of this activity, you should be able to…
Utilize ‘TryLock’ to try to lock a resource without blocking.
Understand deadlock situations slightly better.
Instructions:
The program that is delivered to you takes three arguments in the following form:
Usage: DrinkingGame drinkerCount bottleCount openerCount
Arguments:
drinkerCount                Number of drinkers.
bottleCount                  Number of bottles.
openerCount                  Number of openers.
The drinking game consists of Drinkers, Bottles, and Bottle Openers. During the gameplay drinkers will be constantly trying to drink, which consists of acquiring a bottle and an opener resource. Once a drinker is able to successfully acquire both resources it will take a drink, sleep for a while, then release both resources so another drinker can use them.
When trying to get the resources one of two things may happen: the drinker acquires both resources or the drinker fails to get any resources. Each resource has a mutex that determines if it’s currently in use – if it’s locked then it’s being used by a drinker. The drinker will randomly pick a bottle or an opener as its first resource and lock it. Once the drinker has the first resource it will need to look through the entire pool of resources for the second resource. If the drinker had a bottle as the first resource then it will need to look for an unused opener. It is possible that the drinker cannot find the second resource – in this case the drinker has failed to get both resources.
Project Tasks (TODOs):
You will implement the ‘Starting gun’ and ‘Shutting down’ logic for detached threads,  .
Start detached drinker threads.
Implement ‘Starting gun’ logic for drinker threads.
Implement ‘Firing’ of ‘Starting gun’ logic in main
Implement ‘Shutting down’ logic for drinker threads. You may want to temporarily comment out the call to ‘StartDrinker’ until you know you’re able to start and shutdown the drinker threads.
Cleanup in main
Make ‘TryToGetResources’ fail
Implement ‘TryToDrink’ synchronization
Implement ‘StartDrinker’ synchronization
Implement ‘TryToGetResources’ logic
Code Conventions:
No global, static or atomic types
No memory leaks

Posted in Uncategorized

Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount