Book Image

C++ Multithreading Cookbook

By : Miloš Ljumović
Book Image

C++ Multithreading Cookbook

By: Miloš Ljumović

Overview of this book

<p>Creating multithreaded applications is a present-day approach towards programming. With the power of C++, you can easily create various types of applications and perform parallelism and optimizations in your existing work. This book is a practical, powerful, and easy-to-understand guide to C++ multithreading. You will learn how to benefit from the multithreaded approach and enhance your development skills to build better applications. This book will not only help you avoid problems when creating parallel code, but also help you to understand synchronization techniques. The end goal of the book will be to impart various multithreading concepts that will enable you to do parallel computing and concurrent programming quickly and efficiently.</p>
Table of Contents (17 chapters)
C++ Multithreading Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

The Barrier class


Among the synchronization base classes for task coordination, an excellent feature of .NET is the Barrier class. Even though locking is an excellent mechanism, you will almost certainly find yourself in a situation where some very complex task issues another mechanism that you would need to solve successfully. The Barrier class enables you to temporarily stop (pause) execution of a task or a collection of tasks at a certain point in the application and continue when all tasks reach that point. For synchronization, this feature is important in order for a series of multiple tasks to be executed in parallel steps.

When an application creates a Barrier object, it has to specify the number of tasks in set that will be synchronized. This value can be observed as a task counter that is internally maintained inside the Barrier object. This value can be incremented using the Barrier::AddParticipant method, or decremented using the Barrier::RemoveParticipant method. When the task...