Page 1 :
Process vs. Thread, Process, , Thread, , 1.Process cannot share the same, memory area(address space), , 1.Threads can share memory and files., , 2.It takes more time to create a process, , 2.It takes less time to create a thread., , 3.It takes more time to complete the execution 3.Less time to terminate., and terminate., 4.Execution is very slow., 5.It takes more time to switch between, two processes., , 4.Execution is very fast., 5.It takes less time to switch between two, threads., , 6.System calls are required to communicate, 6.System calls are not required., each other, 7.It requires more resources to execute., , 7.Requires fewer resources., , 8.Implementing the communication, between processes is bit more difficult., , 8.Communication between two threads are, very easy to implement because threads, share the memory, , 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., Advantages:, User-level threads do not require modification to operating systems., Simple Representation: Each thread is represented simply by a PC, registers, stack, and a small control block, all stored in the user process address space., Simple Management: This simply means that creating a thread, switching between, threads and synchronization between threads can all be done without intervention of the, kernel., Fast and Efficient: Thread switching is not much more expensive than a procedure call., Disadvantages:, There is a lack of coordination between threads and operating system kernel., User-level threads require non-blocking systems call i.e., a multithreaded kernel., Kernel-Level Threads, In this method, the kernel knows about and manages the threads. Instead of thread table in, each process, the kernel has a thread table that keeps track of all threads in the system., Operating Systems kernel provides system call, to, create, and, manage, threads, . Advantages:, Because kernel has full knowledge of all threads, Scheduler may decide to give more, time to a process having large number of threads than process having small number of, threads., Kernel-level threads are especially good for applications that frequently block., Disadvantages:, The kernel-level threads are slow and inefficient. For instance, threads operations, are hundreds of times slower than that of user-level threads.
Page 2 :
Since kernel must manage and schedule threads as well as processes. It require a full, thread control block (TCB) for each thread to maintain information about threads. As a, result there is significant overhead and increased in kernel complexity., , Multithreading Models, Many systems provide support for both user and kernel threads, resulting in, different multithreading models. We look at three common types of threading, implementation., Many-to-One Model, The many-to-one model maps many user-level threads to one kernel thread. Thread, management is done in user space, so it is efficient, but the entire process will block if a, thread makes a blocking system call. Also, because only one thread can access the kernel, at a time, multiple threads are unable to run in parallel on multiprocessors., One-to-one Model, The one-to-one model maps each user thread to a kernel thread. It provides more, concurrency than the many-to-one model by allowing another thread to run when a thread, makes a blocking system call; it also allows multiple threads to run in parallel on, multiprocessors. The only drawback to this model is that creating a user thread requires, creating the corresponding kernel thread. Because the overhead of creating kernel threads, can burden the performance of an application, most implementations of this model restrict, the number of threads supported by the system. Windows NT, Windows 2000, and OS/2, implement the one-to-one model., Many-to-Many Model, The many-to-many model multiplexes many user-level threads to a smaller or equal, number of kernel threads. The number of kernel threads may be specific to either a, particular application or a particular machine (an application may be allocated more kernel, threads on a multiprocessor than on a uniprocessor). Whereas the many-to-one model, allows the developer to create as many user threads as she wishes, true concurrency is not, gained because the kernel can schedule only one thread at a time. The one-to-one model, allows for greater concurrency, but the developer has to be careful not to create too many, threads within an application (and in some instances may be limited in the number of, threads she can create). The many-to-many model suffers from neither of these, shortcomings: Developers can create as many user threads as necessary, and the, corresponding kernel threads can run in parallel on a multiprocessor., , (Diagram of many-to-one model, one-to-one model and many-to-many model), Simultaneous Multithreading, Hyperthreading by intel