The thread library – an introduction
The main library to create and manage threads in C++ is the thread library. First, let’s go through a recap about threads. Then we will dive into what the thread library offers.
What are threads? Let’s do a recap
The purpose of threads is to execute multiple simultaneous tasks in a process.
As we have seen in the previous chapter, a thread has its own stack, local data, and CPU registers such as Instruction Pointer (IP) and Stack Pointer (SP), but shares the address space and virtual memory of its parent process.
In the user space, we can differentiate between native threads and lightweight or virtual threads. Native threads are the ones created by the OS when using some kernel APIs. The C++ thread objects create and manage these types of threads. On the other hand, lightweight threads are like native threads, except that they are emulated by a runtime or library. In C++, coroutines belong to this group. As described...