Wednesday, November 18, 2009

Summary









Summary


Multithreaded program development is much simpler if you use well-understood and familiar programming models and techniques. This chapter has shown the utility of the condition variable model and has solved several relatively complex but important programming problems. APCs allow one thread to signal and cause actions in another thread, which allows thread cancellation so that all threads in a system can shut down properly.


Synchronization and thread management are complex because there are multiple ways to solve a given problem, and the different techniques involve complexity and performance trade-offs. The three-stage pipeline example was implemented several different ways in order to illustrate the options.


Use of careful program design and implementation is the best way to improve program quality. Overdependence on testing and debugging, without attention to detail, can lead to serious problems that may be very difficult to detect and fix.


Looking Ahead


Chapter 11 shows how to use Windows named pipes and mailslots to communicate between processes and threads in those processes. The major example is a client/server system where the server uses a pool of worker threads to service client requests. Chapter 12 then implements the same system using Windows Sockets, extending Chapter 11's client/server system to the use of standard protocols. The server also uses a DLL in-process server and creates thread-safe DLLs.


Additional Reading


David Butenhof's Programming with POSIX Threads was the source of much of the information and programming guidelines at the end of the chapter. The threshold barrier solution, Program 10-1 and 10-2, was adapted from Butenhof as well.


"Strategies for Implementing POSIX Condition Variables in Win32," by Douglas Schmidt and Irfan Pyarali (posted at http://www.cs.wustl.edu/~schmidt/win32-cv-1.html), discusses Win32 (Windows) event limitations along with condition variables emulation, thoroughly analyzing and evaluating several approaches. However, this material was written before SignalObjectAndWait became available, so a great deal of effort is expended in avoiding missed signals. Reading this paper will increase your appreciation of the new function. Another paper by the same authors (http://www.cs.wustl.edu/~schmidt/win32-cv-2.html) builds object-oriented wrappers around Windows synchronization objects to achieve a platform-independent synchronization interface. The open source Pthreads implementation, which is based on the Schmidt and Pyarali work, is available at http://sources.redhat.com/pthreads-win32/.









    No comments: