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

Communicating through the pipe object


Besides message passing, Windows offers other ways to communicate and share data between processes and threads. One of these ways is the pipe object. Pipe is the object in memory that the processes use for their communication. The process that creates a pipe is the pipe server. A process that connects to a pipe is a pipe client. One process writes information to the pipe, and then another process reads the information from the pipe.

We will implement a small client-server example. One process will be a server; another one will be a client. The server will run for an infinite period of time. We will use the pipe object for process communication. Every time the client connects, the server needs to accept the connection and send a welcome message, while the client needs to receive the server's welcome message and make a request to the server again by sending a simple message.

Getting ready

Make sure that Visual Studio is up and running.

How to do it...

Now,...