Threads are virtual units that represent a single sequence of instructions to be processed by a processor core. We can use threads to perform multiple computations concurrently in a process called multithreading.

Each thread has its own program counter register. Oftentimes they’re executing a different function and are almost always executing a different instruction from other threads. They also have their own stacks and stack pointers, but they are able to share global variables in memory (via pointers). Because of this, we have to be careful for threads to not conflict in reads/writes to the same non-atomic memory, because there will be undefined behaviour if they update the same variable at the same time.

Sub-pages