What Does Multithreading Mean?
Multithreading is a type of execution model that allows multiple threads to exist within the context of a process such that they execute independently but share their process resources. A thread maintains a list of information relevant to its execution including the priority schedule, exception handlers, a set of CPU registers, and stack state in the address space of its hosting process.
Multithreading is also known as threading.
Techopedia Explains Multithreading
Threading can be useful in a single-processor system by allowing the main execution thread to be responsive to user input, while the additional worker thread can execute long-running tasks that do not need user intervention in the background. Threading in a multiprocessor system results in true concurrent execution of threads across multiple processors and is therefore faster. However, it requires more careful programming to avoid non-intuitive behavior such as racing conditions, deadlocks, etc.
Operating systems use threading in two ways:
- Pre-emptive multithreading, in which the context switch is controlled by the operating system. Context switching might be performed at an inappropriate time, Hence, a high priority thread could be indirectly pre-empted by a low priority thread.
- Cooperative multithreading, in which context switching is controlled by the thread. This could lead to problems, such as deadlocks, if a thread is blocked waiting for a resource to become free.
The 32- and 64-bit versions of Windows use pre-emptive multithreading in which the available processor time is shared such that all the threads get an equal time slice and are serviced in a queue-based mode. During thread switching, the context of a pre-empted thread is stored and reloaded in the next thread in the queue. The time slice is so short that the running threads seem to be executing in parallel.