A thread is a single sequence stream within in a process. Because threads have some of the properties of processes, they are sometimes called lightweight processes. In many respect, threads are popular way to improve application through parallelism. The CPU switches rapidly back and forth among the threads giving illusion that the threads are running in parallel. Like a traditional process i.e., process with one thread, a thread can be in any of several states (Running, Blocked, Ready or terminated). A thread consists of a program counter (PC), a register set, and a stack space. Threads are not independent of one other like processes. Threads shares address space, program code, global variables, OS resources with other thread.
Fig: Process with single thread Fig: Process With multiple thread
- Process with multiple threads makes a great server (e.g. print server)
- Increase responsiveness, e. with multiple threads in a process, if one threads blocks then other can still continue executing
- Sharing of common data reduce requirement of inter-process communication
- Proper utilization of multiprocessor by increasing concurrency
- Threads are cheap to create and use very little resources
- Context switching is fast (only have to save/reload PC, Stack, SP, Registers)