Exercises
101. | Revise Program 10-1 so that it does not use the SignalObjectAndWait function; test the result on a Windows 9x system. |
102. | Modify eventPC (Program 8-2) so that there can be multiple consumers and so that it uses the condition variable model. Which event type is appropriate? |
103. | Change the logic in Program 10-2 so that the event is signaled only once. |
104. | Replace the mutex in the queue object used in Program 10-2 with a CS. What are the effects on performance and throughput? The solution is on the book's Web site, and Appendix C contains experimental data. |
105. | Program 10-4 uses the broadcast CV model to indicate when the queue is either not empty or not full. Would the signal CV model work? Would the signal model even be preferable in any way? Appendix C contains experimental data. |
106. | Experiment with the queue lengths and the transmitter-receiver blocking factor in Program 10-5 to determine the effects on performance, throughput, and CPU load. |
107. | Modify Program 10-3 through 10-5 to conform to the Windows naming style used elsewhere in this book. |
108. | For C++ programmers: The code in Program 10-3 and 10-4 could be used to create a synchronized queue class in C++; create this class and modify Program 10-5 to test it. Which of the functions should be public and which should be private? |
109. | Study the performance behavior of Program 10-5 if CRITICAL_SECTIONs are used instead of mutexes. |
1010. | Improve Program 10-5 so that it is not necessary to terminate the transmitter and receiver threads. The threads should shut themselves down. |
1011. | The Web site contains MultiSem.c, which implements a multiple-wait semaphore modeled after the Windows objects (they can be named, secured, and process shared, and there are two wait models), and TestMultiSem.c is a test program. Build and test this program. How does it use the condition variable model? Is performance improved by using a CRITICAL_SECTION? What are the invariants and condition variable predicates? |
1012. | Illustrate the various guidelines at the end of this chapter in terms of bugs you have encountered or in the defective versions of the programs provided on the Web site. |
1013. | Read "Strategies for Implementing POSIX Condition Variables in Win32" by Schmidt and Pyarali (see the Additional Reading section). Apply their fairness, correctness, serialization, and other analyses to the condition variable models (called "idioms" in their paper) in this chapter. Notice that this chapter does not directly emulate condition variables; rather, it emulates condition variable usage, whereas Schmidt and Pyarali emulate condition variables used in an arbitrary context. |
1014. | Two projects on the Web site, batons and batonsMultipleEvents, show alternative solutions to the problem of serializing thread execution. The code comments give background and acknowledgments. The second solution associates a unique event with each thread so that specific threads can be signaled. The implementation uses C++ in order to take advantage of the C++ Standard Template Library (STL). Compare and contrast these two solutions, and use the second as a means to become familiar with the STL. |