450 - The Cow Simulator? In this homework you will be exploring threads, command line interfaces and shared memory via a kind of Cow simulator. Your program should spawn a number of threads equal to a value passed on the command line. For example: ./mycows 3 should spawn 3 threads. You may have an extra thread so that the main thread can simply be waiting on the other threads to exit. Each of these threads corresponds to a single cow available in your herd. Each cow has a unique id corresponding to which stall it will always eat from. For example, the first thread should always eat from stall 0. The second thread from stall 1. In this example, you'll notice that the 3 is passed to the program via the command line. Each cow should keep track of how many times it doesn't eat and how much it does eat. When a cow arrives at its stall, it will only eat if the id in that stall matches the unique id given to your herd. So, if your herd id is 27, cow 0 will only eat if stall 0 has the id 27 in it. In addition, the amount the cow can eat is listed attached to that specific stall. A cow won't eat at a stall more than once per hour. So it if happens to show up at the stall twice in an hour, it should ignore the stall and wait until the next hour. How this all works! An array of stalls is stored in shared memory with key 31337. Your program should attach to that shared memory. The values in the shared memory are updated periodically by an external program. Thread "i" in your program should keep track of the last hour a cow ate at a stall (you can assume the hour is never negative). It should go to stall i and check the id with your herd id. If they are different, the cow starves that hour. If they are the same, the cow eats the 'amount.' You should keep track of these values for reporting later. You'll find it useful in debugging to work with one thread at first and simply output those statistics each time the cow runs. Stalls in shared memory are represented by: struct Stall { int id; int amount; int hour; }; Provide a mechanism to close all threads and report your statistics. You might handle this with signals, Remember, your threads can communicate via global memory. Unique IDs: SR 0 Doc ZB 1 TF 2 JH 3 KL 4 MSM 5 Stag McDyre SM 6 Steve McFall JM 7 HR 8 RT 9 JY 10 To see the current simulation of the stalls by hand, you can visit http://albert.washcoll.edu/~sramsey2/cows.txt This file will be clobbered roughly every 20 minutes.