This exam is open-book, open-notes, open-computer, open-Internet, but closed-other-people. You may, however, ask Jeff Ondich questions.
For this problem, you will use as many binary semaphores as you see fit to force a particular kind of synchronization between three threads.
To get started, take a look at mutexTester.c. This program shows you how to spawn a child thread and how to allocate and manipulate a mutex_t variable (that is, a binary semaphore).
Now write your own program that spawns two child threads, say Child 1 and Child 2. Each thread (including the parent thread) should then enter an infinite loop, printing an identifying message such as "Hi, I'm Child 1." The trick is that your program should print out the identifying messages in the order: Parent, Child 1, Parent, Child 2, Parent, Child 1, Parent, Child 2, etc. You may use as many mutex_t variables as you wish, but no other local or global variables of any kind.
Please submit a paper copy of your code with your exam, and an
electronic copy via HSP. You should feel free to make your
identifying messages more interesting than mine.
|
|