Page 70 - DCAP103_Principle of operating system
P. 70

Unit 3: Process Management-II



                                                                                                  Notes
            3.1.1 Processes vs Threads
            As we mentioned earlier that in many respect threads operate in the same way as that of
            processes. Some of the similarities and differences are:

            3.1.1.1 Similarities
               •  Like processes threads share CPU and only one thread active (running) at a time.

               •  Like processes, threads within a processes, threads within a processes execute sequentially.
               •  Like processes, thread can create children.

               •  And like process, if one thread is blocked, another thread can run.
            3.1.1.2 Differences

               •  Unlike processes, threads are not independent of one another.
               •  Unlike processes, all threads can access every address in the task.

               •  Unlike  processes,  threads  are  design  to  assist  one  other.  Note  that  processes  might  or
                 might not assist one another because processes may originate from different users.
            3.1.2 Why Threads?

            Following are some reasons why we use threads in designing operating systems.
               1.  A process with multiple threads makes a great server for example printer server.

               2.  Because  threads  can  share  common  data,  they  do  not  need  to  use  interprocess
                 communication.

               3.  Because of the very nature, threads can take advantage of multiprocessors.
            3.1.2.1 Threads are Cheap in the Following Sense:

               1.  They only need a stack and storage for registers therefore, threads are cheap to create.
               2.  Threads use very little resources of an operating system in which they are working. That
                 is, threads do not need new address space, global data, program code or operating system
                 resources.
               3.  Context switching are fast when working with threads. The reason is that we only have
                 to save and/or restore PC, SP and registers.
            But  this  cheapness  does  not  come  free—the  biggest  drawback  is  that  there  is  no  protection
            between threads.

            3.1.3 User-level Threads
            User-level  threads  implement  in  user-level  libraries,  rather  than  via  systems  calls,  so  thread
            switching does not need to call operating system and to cause interrupt to the kernel. In fact, the
            kernel knows nothing about user-level threads and manages them as if they were single-threaded
            processes.









                                             LOVELY PROFESSIONAL UNIVERSITY                                    63
   65   66   67   68   69   70   71   72   73   74   75