A thread is similar to a process, with the main distinctions being the following:
- Threads are contained within processes
- Threads inherently share a memory space with other threads of the same process, while processes do not share resources unless explicitly told to (using inter-process communication mechanisms)
Like processes, however, threads are scheduled for execution at any time by the operating system. This may mean executing in parallel with other threads, leading to performance optimizations if properly used, but at the expense of introducing threading-specific logic bugs, such as race conditions and deadlock.
The goal of this section is to briefly review POSIX threads. These largely influenced the design of C++ threads, which will be discussed later.