Threads
A thread is one of the most basic building blocks of concurrent code. It is a part of a program that can execute threads concurrently to the rest of the code. Each thread can share resources, such as memory and file handles. In a system that allows threading, each process is divided into one or more threads. If the program was not written to use multiple threads and run concurrently, then it is called a single thread process.
In a single CPU system, multiple threads are interleaved, with each thread receiving a small amount of time called a quantum. This is called time slicing and happens so quickly that to the user, it appears as if the threads are running in parallel. For example, one thread might be updating a file while another is redrawing a window on the screen. To the user, they appear in parallel but may only be running sequentially. It is the same principle that is applied to running processes using the operating system scheduler.
When a thread expires, it's referred...