Channels ▼
RSS

Multithreading Applications in Win32


July 1997/Multithreading Applications in Win32

Title: Multithreading Applications in Win32: The Complete Guide
Author: Jim Beveridge and Robert Wiener
Publisher: Addison-Wesley Developers Press, 1997
Pages: 400, paperback, with CD-ROM
ISBN: 0-201-44234-5
Price: $39.95

When I started looking at threads programming in Win32, I found the subject very complex, and I did not find enough material that explained it well. The Windows documentation, for example, was not very helpful. Programming threads is not simple, but the authors of this book have worked very hard to simplify it as much as possible and yet still provide a competent, non-trivial explanation. This book covers all aspects of programming threads in Win32 (including the Windows NT 4.0 API) except for security. It also provides practical examples of threads programming in applications, including Internet web servers and Microsoft's COM (Component Object Model) applications.

I found this book to be very well organized. It covers a broad spectrum of multithreading issues in three logical parts.

Part I is named "Threads in Action." It deals with basic threading concepts, such as creating and destroying threads, synchronization, deadlock, and thread priority. There is also a chapter devoted to overlapped I/O and related topics, such as Asynchronous Procedure Calls (APCs). I especially liked this section's treatment of Win32 synchronization variables (critical sections, mutexes, semaphores, etc.) — this is often one of the most confusing aspects of Win32 threads programming and the book handles it very well.

Part II is "Multithreading Tools and Tricks." The issues covered in this section include use of threads in C++ classes, threads and the C runtime library (particularly the Microsoft Visual C++ implementation of a thread-safe C runtime library), threads and interprocess communications (IPC), debugging multithreaded applications, threads in dynamic link libraries (DLLs), and multithreading GUI applications. This section also covers use of threads in Microsoft Foundation Classes (MFC) applications. There are some limitations in the way the MFC thread classes encapsulate threads; this section points them out and presents workarounds. Another topic that deserves special treatment is that of maintaining data consistency between different threads, which may be doing different things (e.g. reading and writing) to the same data. This section devotes a whole chapter to this topic. Also covered in this section is performance monitoring in Windows NT and Windows 95.

Part III is called "Multithreading in Real World Applications." This section covers three main topics: planning a multithreaded application, multithreading Internet web server applications using Microsoft's Internet Server API (ISAPI), and multithreading COM applications. The chapter on planning gives guidelines on a wide range of issues, including scalability using the Windows NT symmetric multiprocessing (SMP) facility, multithreading applications that access databases using the ODBC standard, and use of third-party libraries and components such as OLE controls and report generators. The chapter on COM, ActiveX, and OLE goes into some depth in explaining the various threading models that may be used to multithread a COM application.

Most of the material is presented with examples in C but there is also a good treatment of threads usage with C++. There are lots of examples, and they are explained in detail. The full source code is available on the bundled CD; the portions of the source code relevant to a particular discussion are presented in the book. Many of the examples use Visual C++ 4.x, this obviously being the writers' compiler of choice. However, even if you don't use this compiler, or MFC, you can still benefit from this book. The examples do not rely heavily on MFC, and the C examples are fairly generic with respect to compilers.

You might be disappointed, though, if you have concerns about security. For example, suppose you are writing a multithreaded server application for Windows NT. The security attributes of threads may be very important in this case, but this book ignores the subject. I find this surprising, since the book claims to be a complete guide. But, the authors plainly state in the book that security will not be discussed.

Who Will Benefit

The book is very easy to read. It has a personal touch — you feel the authors are talking to you. This book also has a tutorial feel to it. It combines narration of facts with FAQs (Frequently Asked Questions). 56 FAQs are listed just after the table of contents. These are answered in relevant parts of the book as a natural part of presenting the material. The Win32 threads API functions are explained very well — which makes them easier to understand than the Win32 documentation. The authors have also not been shy to criticize some of the recommendations of the Win32 threads documentation. A typical example is the recommendation that in a multithreaded Multiple Document Interface (MDI) application each MDI child window could have its own thread. The writers have not only gone to great lengths to explain why this is not such a great idea, but have also presented an alternate, more efficient threads implementation.

If you are an experienced C/C++ Windows programmer who wants to extend your expertise and give your applications more power with threads programming, then this book is for you. This will become apparent as soon as you begin reading the book. The very first example uses a linked list to illustrate a race condition. The authors assume that you are familiar with linked lists and how they are set up. UNIX programmers who are porting code to Win32 will surely benefit from the tips and comparisons with UNIX threads and processes. (There are not many of these comparisons, though).

My overall evaluation is that this book provides excellent coverage of the threads implementation in Win32. You will find it useful whether you are a novice threads programmer or an experienced one. You will also find this book useful if you want to use threads in your MFC applications. The examples are easy to follow and the accompanying CD will give you a head start. Of course, you will still have to refer to the Win32 documentation for more material on the security aspects of threads. There are relatively few books available on the subject of multithreading. This book will certainly reduce your headaches as you seek to use threads to improve your applications. o

Michael K Larbi is a software engineer working with Quest Information Systems Ltd in London, England, to develop real-time financial systems. He may be reached at Michael_Larbi@msn.com.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video