Thread (OS)

A thread is a strand of execution within a process, a process may have many threads executing ‘at the same time’.

For multi-threaded processes, the process has unique values for the registers, stack, and program counter for each thread. Processes are largely independent of each other and do not share memory, however threads share the address space of the process. They have access to the same heap.

Link to original

In the kernel itself, the OS schedules threads not processes.

It is the sharing of data between threads that causes issues related to the class of problems related to synchronisation.

Single CPU systems

A single CPU system can only execute one task at a time, we can however use a scheduler to switch between them to appear as if tasks are being performed simultaneously. However, only one task is ever performed at one instant.

If threads were to be introduced to this model, threads would have to take turns to perform the task it is that they are implementing.

Multi-core processors

Multi-core processors are processors with more cores (CPUs) that can execute in parallel. The OS and CPU can now schedule multiple process to literally execute at the same time by allocating them to different cores.

User and Kernel threads

User Thread

User threads are threads that the user creates (such as in Java / pthreads library).

The operating system will generally map user threads to kernel threads for execution in a one-to-one fashion. But there are possible many-to-one and many-to-many mappings but these are less common.

Link to original

Kernel Thread

Kernel threads are threads that are owned by the kernel itself, they are the basic unit of execution for the OS.

Link to original