[C++] Multithreading and Concurrency: INTRODUCTION

A simple guide to learn C++ multithreading and concurrency without too many headaches

Valentina Di Vincenzo
The Startup

--

When I started studying C++ multithreading I was feeling confused and lost. The complexity of the program was blooming (yes, like a beautiful flower), the non-deterministic behavior of concurrency was killing me and everything was foggy. So I get you and I got you: here is a simple guide to learn C++ concurrency and multithreading without too many headaches (you can find the roadmap at the end of the article).

Today, let’s quickly refresh some basic concepts and then taste a bit of concurrent code.

1. What is a thread?

Upon creation, each process has a unique thread of execution called main thread. It can ask the Operating System to create other threads, that share the same address space of the parent process (code section, data section, other operating-system resources, such as open files and signals). On the other hand, each thread has its own thread ID, stack, register set, and program counter. Basically a thread is a lightweight process, switching between threads is faster and IPC is easier.

2. What is concurrency?

--

--