John Hacker is a hardware designer who came up with a great idea for a hardware instruction that he claims can help in solving the critical section problem. It is called atomic counters. An atomic counter is a variable in memory that can be sampled and incremented in one atomic operation. Also, it can be reset to 0. The Big Fish Little Fish pet store is having some problems keeping their hamsters happy.
Hamsters like to eat, sleep, and run their wheel.
Hamsters must eat before running their wheel, so they have energy to run their wheel. Although many hamsters are kept in a single cage, only three can eat at the food dish at the same time and only one can run the wheel. After running the wheel, a hamster might sleep or it might eat again. You are to write the hamster thread code using semaphores. CPU Scheduling 1.