Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

Chapter 4 Threads Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
Threads, SMP, and Microkernels
CHAPTER 5 THREADS & MULTITHREADING 1. Single and Multithreaded Processes 2.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 7 Chapter 4: Threads (cont)
Day 10 Threads. Threads and Processes  Process is seen as two entities Unit of resource allocation (process or task) Unit of dispatch or scheduling (thread.
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 5: Threads 9/29/03+ Overview Benefits User and Kernel Threads Multithreading.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples.
3.5 Interprocess Communication
Threads CSCI 444/544 Operating Systems Fall 2008.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Process Concept An operating system executes a variety of programs
A. Frank - P. Weisberg Operating Systems Threads Implementation.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Threads Chapter 4. Modern Process & Thread –Process is an infrastructure in which execution takes place  (address space + resources) –Thread is a program.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Processes Part I Processes & Threads* *Referred to slides by Dr. Sanjeev Setia at George Mason University Chapter 3.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides.
Operating Systems Lecture 09: Threads (Chapter 4)
Operating System Principles Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Chapter 4: Threads. From Processes to Threads 4.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Threads.
Thread. A basic unit of CPU utilization. It comprises a thread ID, a program counter, a register set, and a stack. It is a single sequential flow of control.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Threads, SMP, and Microkernels Chapter 4. 2 Outline n Threads n Symmetric Multiprocessing (SMP) n Microkernel n Linux Threads.
Threads, Thread management & Resource Management.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
Threads G.Anuradha (Reference : William Stallings)
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
1 Lecture 4: Threads Advanced Operating System Fall 2010.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Chapter 4: Threads. 2 Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads.
Lecture 5: Threads process as a unit of scheduling and a unit of resource allocation processes vs. threads what to program with threads why use threads.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Department of Computer Science and Software Engineering
Thread By Group III Kathryn Bean and Wafa’ Jaffal.
Operating Systems: Internals and Design Principles
Module 2.0: Threads.
Cooperating Processes The concurrent processes executing in the operating system may be either independent processes or cooperating processes. A process.
Threads. Thread A basic unit of CPU utilization. An Abstract data type representing an independent flow of control within a process A traditional (or.
Saurav Karmakar. Chapter 4: Threads  Overview  Multithreading Models  Thread Libraries  Threading Issues  Operating System Examples  Windows XP.
Operating System Concepts
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution-
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
CISC2200 Threads Fall 09. Process  We learn the concept of process  A program in execution  A process owns some resources  A process executes a program.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Lecture 5. Example for periority The average waiting time : = 41/5= 8.2.
OPERATING SYSTEM CONCEPT AND PRACTISE
Day 12 Threads.
Chapter 4 Threads.
Threads & multithreading
Operating System Concepts
Lecture 10: Threads Implementation
Threads Chapter 4.
Threads Chapter 4.
Lecture 10: Threads Implementation
Presentation transcript:

Threads

Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics are separable Processes (or tasks) are allocated resources Threads (or lightweight processes) are dispatched

What is a thread?  A set of threads have shared access to the resources of a process (including memory)  Each thread has its own thread control block (TCB). Since each thread has its own TCB, it also has its own PC, GP registers, and state.  Each thread also has its own kernel stack, user stack, and space for static variables  A thread is a unit of dispatching within a process.

Threads in modern operating systems  Single-threading - Only 1 process (DOS) or 1 thread per process (flavors of UNIX).  Multi-threading - More than 1 thread in 1 process and many processes - Solaris, W2K, LINUX.  One process many threads – Java runtime environment.

Why threads?  Less time to create a thread  Less time to delete a thread  Switching between threads of the same process is faster  Communication between threads within a single process is more efficient than communication between processes  On shared-memory multi-processor systems, threads can be scheduled on different processors

Thread examples  Web server  Word processor  Others?

Figure 4.2 Thread life cycle. [Deitel et al] 4.4 Thread States: Life Cycle of a Thread

User level threads and kernel level threads

User level threads (Many to one mapping)  Implement thread creation/manipulation using procedure calls to a user-level library rather than system calls. ULTs can run on any OS, as long as the thread library is available.  The thread management is done by the application and the kernel is unaware of threads. Allows the user to use scheduling algorithms that are more appropriate to the application.  Switching between threads is done without invoking the kernel and the only context that needs to be saved is the program counter, user registers and stack pointers. (Threads voluntarily give up the CPU).

User level threads (Many to one mapping)  OS is unaware of the threads and schedules independent of number of threads per process. If the application does require system calls, then when a thread gets blocked, process itself gets blocked.  In a multi-processing environment, the kernel cannot schedule different threads of a process on different processors as it is unaware of the threads.

Kernel-level threads (KLT) (One to one mapping)  OS is aware of all the threads. Switch between threads requires a mode switch - still inexpensive as the context is still small - more expensive than ULT as mode switch required.  OS schedules the threads and hence if a thread blocks a process need not block.  Can be efficiently used in a multi-processing environment.  Less portable as the code has to be re-written to use the API of the under-lying OS. Use of POSIX threads reduces this problem.  A lot of overhead on the OS as a process may have 100s of threads and this would result in thousands of dispatch units for the OS to manage.  Linux supports the one-to-one i.e. KLT model. Efficient mode (context) switching mechanism is available.

Combined approach (many to many or m-to-n approach)  Windows XP and old versions of Solaris  A process may have a number of ULTs and these can be mapped to smaller number or equal number of KLTs.  By allowing the mapping, we can reduce the number of threads, the OS sees. The programmer can select which threads (blocking threads) are seen by the kernel separate from the non-blocking.  Creation, synchronization etc. are done at the application level.

If one were to generalize,  It could be said that ULTs result in a much faster execution time than KLTs which are much faster than processes.