3

Threads

Recall from the previous topic that processes are programs that are being executed by being loaded to memory.

To increase the efficiency of running a program that contains similar tasks (like those found in loops) or independent tasks, operating systems support the execution of threads.

A thread is a basic unit of CPU execution, consisting of a thread ID, a program counter, a stack, and a set of registers. In the past, most processes were single-threaded; that is, each process had exactly one unit of execution, but most contemporary OSs support multi-threading (see the definition in 2 slides from now.)

Threads that belong to the same process will share the same text, data, and heap memory sections and the same process resources, including access to the files that were opened by the process and devices used by the process. The stack memory section, however, isn't common to all threads, as each thread has its own stack as mentioned above.