Book Image

Learning Boost C++ Libraries

By : Arindam Mukherjee
Book Image

Learning Boost C++ Libraries

By: Arindam Mukherjee

Overview of this book

Table of Contents (19 chapters)
Learning Boost C++ Libraries
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating concurrent tasks with Boost Thread


Consider a program that prints greetings in different languages. There is one list of greetings in Anglo-Saxon languages, such as English, German, Dutch, Danish, and so on. There is a second list of greetings in Romance languages, such as Italian, Spanish, French, Portuguese, and so on. Greetings from both language groups need to be printed, and we do not want to delay printing the greetings from one group because of the other, that is, we want to print greetings from both the groups concurrently. Here is one way to print both the groups of greetings:

Listing 10.1: Interleaved tasks

 1 #include <iostream>
 2 #include <string>
 3 #include <vector>
 4
 5 int main()
 6 {
 7   typedef std::vector<std::string> strvec;
 8
 9   strvec angloSaxon{"Guten Morgen!", "Godmorgen!", 
10                    "Good morning!", "goedemorgen"};
11
12   strvec romance{"Buenos dias!", "Bonjour!", 
13                  "Bom dia!", "Buongiorno!"};...