Monthly Archives: August 2011

Windows with C++: The Windows Thread Pool and Work

My latest Windows with C++ column, The Windows Thread Pool and Work, is now available in the August 2011 issue of MSDN Magazine. It is also available online. From the article:

Concurrency means different things to different people. Some folks think in terms of agents and messages—cooperating but asynchronous state machines. Others think in terms of tasks, usually in the form of functions or expressions that may execute concurrently. Still others think in terms of data parallelism, where the structure of the data enables concurrency. You might even consider these complementary or overlapping techniques. Regardless of how you view the world of concurrency, at the heart of any contemporary approach to concurrency is a thread pool of one form or another.

I hope you enjoy it. This is the first in a series on the Windows thread pool API. It also takes advantage of the unique_handle class template I introduced in my July 2011 column so be sure to read that first.

You can find links to more of my articles here.

Windows with C++: C++ and the Windows API

A few readers have left comments on my Windows with C++ column for July 2011. I was hoping to respond but there is a problem with the commenting infrastructure that prevents me from leaving a comment. If you missed it, you can read it online now.

Windows with C++: C++ and the Windows API

In this issue, I introduce the unique_handle class template. Here are a few questions I received along with my answers.

Juan Carlos Trimiño asks about the empty throw exception specification as it relates to Boost and Visual C++.

Boost is designed to work with a large variety of C++ compilers. The Windows with C++ column is about Windows and Visual C++. You can of course use the techniques I illustrate with other compilers but you may need to optimize certain practices for your compiler of choice. The Visual C++ compiler will in all likelihood inline all of the functions in the unique_handle class template in which case the throw specification would have no effect. I prefer not to base too many coding decisions on whether or not a function will be inlined. I do not want to take any chances as the performance impact on large code bases can be significant. In the future we will be able to use “noexcept” from C++0x as a more portable and semantically correct way of expressing the same thing.

DavidTM asks about the relevance of the Windows API in today’s world of MFC, .NET and C#.

Libraries like MFC and to a lesser degree ATL are very old. I first learned how to use MFC when I was in my teens. It was designed around an early version of C++ that is not representative of modern C++ style. You can of course still use MFC but I do not recommend it as modern C++ can do a better job of supporting the Windows developer. As for .NET, that is a choice you need to make weighing up your experience, the level of productivity and assistance you expect, and your performance requirements. See my interview for more on this.

Juan Carlos Trimiño asks another question about auto_ptr.

C++0x introduces the unique_ptr class template that completely replaces the older auto_ptr class template. You should never again use auto_ptr for anything. If you need an STL container of pointers then use unique_ptr.