Practice concurrent programming in Go.
Beginning of class session 39. (Two point bonus for completing at least feature 4b before class session 37.)
You may choose to pair program on this assignment. If you do that, be sure to give the names of both authors in the comments.
Your overall objective is to implement a simulator for the scenario below using channels and goroutines. The scenario is from John A. Trono. A new exercise in concurrency. SIGCSE Bull., 26(3):8–10, 1994.
Santa Claus sleeps in his shop up at the North Pole, and can only be wakened by either all nine reindeer being back from their year long vacation on the beaches of some tropical island in the South Pacific, or by some elves who are having some difficulties making the toys. One elf’s problem is never serious enough to wake up Santa (otherwise, he may never get any sleep), so, the elves visit Santa in a group of three. When three elves are having their problems solved, any other elves wishing to visit Santa must wait for those elves to return. If Santa wakes up to find three elves waiting at his shop’s door, along with the last reindeer having come back from the tropics, Santa has decided that the elves can wait until after Christmas, because it is more important to get his sleigh ready as soon as possible.
(It is assumed that the reindeer don’t want to leave the tropics, and therefore they stay there until the last possible moment. They might not even come back, but since Santa is footing the bill for their year in paradise… This could also explain the quickness in their delivering of presents, since the reindeer can’t wait to get back to where it is warm.)
The penalty for the last reindeer to arrive is that it must get Santa while the others wait in a warming hut before being harnessed to the sleigh.
Follow these steps to implement your simulation.
Use your SVN client to update your individual SVN repository. You should find a new folder, GoSanta. Within the folder are four files: santa.go, santa_test.go, main.go and Makefile.
The make file provides a few useful targets:
gomake main will compile the main.go program, after which you can execute your simulation by running maingomake clean will clean up all the generated test files and compiler byproducts, except for those from main.gogomake pristine will clean up the compiler byproducts from main.go and all the restgotest will run the unit tests as usualsanta.go. I’ve provided types representing Santa, Elves, and Reindeer, along with basic helper methods for each. You may change the implementation of any of these, but should not change the values printed by the report methods. The values printed will be important when we grade your submission.main.go to see what command line options your simulation should support. In particular, your code must handle variable total number of reindeer (called tr), number of elves needed to wake Santa (called ne), and total number of elves in the workshop (called te).
Implement your simulation by adding code to santa.go. You are free to add more unit test code to santa_test.go as well, though I’m not requiring that. Unit testing concurrent code is challenging and our time is short. (If you’re interested in exploring that, the poorly named testing/script package includes utilities for testing channels.)
Your solution must report on the state of the simulation by calling the provided helper methods at the appropriate times. A complete solution will call every one of the provided reportFoo helper methods.
I strongly encourage you to implement one feature of the simulation at a time and commit after implementing each feature. Here’s a suggested sequence of features to implement:
santa.go to indicate which features you have implemented. Your goal is to implement all of them, but I want to know which features you think you have successfully implemented.Turn-in your work by committing it to your SVN repository. Don’t forget to:
santa.go