Unix process(3) vs. thread


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值