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.
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:
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.
Read More »