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

Managing shared data


All threads in a process have access to the same global memory, so the results of computations performed in one thread are relatively easy to share with other threads. Concurrent read-only operations on shared memory do not require any coordination, but any write to shared memory requires synchronization with any read or write. Threads that share mutable data and other resources need mechanisms to arbitrate access to shared data and signal each other about events and state changes. In this section, we explore the mechanisms for coordination between multiple threads.

Creating and coordinating concurrent tasks

Consider a program that generates the difference between two text files à la the Unix diff utility. You need to read two files, and then apply an algorithm to identify the parts that are identical and the parts that have changed. For most text files, reading both the files and then applying a suitable algorithm (based on the Longest Common Subsequence problem) works...