Problem with existing notion of processes
--Context switch very expensive
--IPC is expensive
--processes are expensive to create ,terminate ,amnage
----------------> Thread
Thread:
1.def:
light weight process
thread of instructions or thread of control
share addres space and other global info. with its process(all thread share same memory space -> no
problems with inter-thread communication)
e.g.: Win32 threads,C-threads,Pthreads
2.similarities & differences
Simi: share CPU and onlu ome thread is active at a time
thread can also create children
one thread is blocked ,another can run
Diff: threads are not independent of one another
all threads can acces every address in shared address space
threads are designed to assist on other,cheap communication of inter-thread communication
3.why
a process with multiple threads make a greate server e.g. printer server
threads can share common data ,no need intereprocess communication
take adv. of multiprocessors to cooperatively complete one task
cheap-->only need stack and storage for register
very little resources of an OS ,no need new address space , global data, etc.
context switching are fast when working with threads
4.Life cycle
Born state -->Ready state (runnable state),Ready to be run
Running state -->Currently running on CPU
Dead state-->When the task is complete
Blocked state-->Waiting for the completion of an I/O request
Waiting state-->Waiting for an event (e.g. for mouse to move)
Sleeping state-->Sleep interval specifies for how long a thread will sleep
e.g. wakes every sleep interval to backup data
5.Operation
Create,Exit,Suspend,Resume,Sleep,Wake,
Join: primary thread created ->when primary thread ends the entire process terminates, killing al threads its
contains-->primary threaad wait for all other threads to exit by joining them-->joining thread blocks
until it joined exits
6.Thread Signal Delivery
Synchronous: occur as direct result of program execution,be delivered to currently executing thread
Asynchronous: occur due to an event typically unrelated to the current instruction