My current C++ compiler is Microsoft's Visual Studio Version 10. This compiler is old enough that it does not support C++11. C++11 supports threads natively, but the earlier version of C++ that is supported by my compiler does not support threads natively. Therefore, I am using boost for thread support. I believe that the support for threads in C++11 is fairly compatible with the support for threads in boost::thread. Therefore, I'm hoping that if ever I upgrade to a compiler that supports C++11, the only thing I would have to do would be to replace the include statements for boost::thread with include statements for std::thread. In order to use boost, you have to download it from http://www.boost.org/users/download/. The download process is very easy, but the installation process is not so easy. To use boost you will need both the header files to be included in your program at compile time and some binary files to be included in your program at link time. It is much easier to install the header files than it is to install the binary files. |
All you have to do for the header files is to point your compiler to wherever you downloaded the files. Preparing the binary files for link time is a much more complicated process than is installing the header files, and the documentation is rather challenging. There are several different ways to prepare the binary files, which is one of the reasons the documentation is so challenging. It's not always very clear which of the several ways to prepare the binary files is the best one to use. I found that I had to compile and link many thousands of modules and the process took several hours to run. There may have been some pre-built executables for Windows that I could have simply pointed to, but if so then I couldn't find them. Also, you can compile and link either 32 bit executables or 64 bit executables, or both. Without quite knowing what I was doing, I ended up compiling and linking only the 64 bit executables and I didn't want to fight through the details and the time of getting both the 32 bit and 64 bit versions working. So if I need to use boost in a program, I have to make my program a 64 bit program even if it could get by as a 32 bit program. |
// This code contains errors. Do not run it until we have // eliminated all the errors. #include "stdafx.h" #include <iostream> #include <boost/thread.hpp> void funct1(); void funct2(); int main() { boost::thread xxxx(funct1); boost::thread yyyy(funct2); return 0; } void funct1() { for (int i = 0; i < 50; i++) std::cout << '?'; std::cout << std::endl; } void funct2() { for (int i = 0; i < 50; i++) std::cout << '!'; std::cout << std::endl; } |
|
This page last edited on 22 Mar 2016.