Chapter 4 Threads.

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
Operating Systems: Internals and Design Principles
Threads Relation to processes Threads exist as subsets of processes Threads share memory and state information within a process Switching between threads.
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.
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Inter-Process Communication  most OSs provide several abstractions for inter- process communication: message passing, shared memory, etc.  communication.
Process Concept An operating system executes a variety of programs
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.
Operating Systems Lecture 09: Threads (Chapter 4)
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Threads, SMP, and Microkernels Chapter 4. 2 Outline n Threads n Symmetric Multiprocessing (SMP) n Microkernel n Linux Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Threads, Thread management & Resource Management.
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Threads G.Anuradha (Reference : William Stallings)
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership: process includes a virtual address space to hold the process image (fig 3.16)
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 Threads, SMP, and Microkernels Chapter Multithreading Operating system supports multiple threads of execution within a single process MS-DOS.
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.
Department of Computer Science and Software Engineering
Thread By Group III Kathryn Bean and Wafa’ Jaffal.
Module 2.0: Threads.
Threads, Thread management & Resource Management.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution-
Processes Chapter 3. Processes in Distributed Systems Processes and threads –Introduction to threads –Distinction between threads and processes 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.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Chapter 4 – Thread Concepts
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4: Threads.
CS 6560: Operating Systems Design
Day 12 Threads.
Chapter 4 – Thread Concepts
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 4: Multithreaded Programming
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 4: Threads.
Operating System Concepts
Operating Systems Processes and Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Threads, SMP, and Microkernels
Lecture 10: Threads Implementation
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Threads Chapter 4.
Lecture 4- Threads, SMP, and Microkernels
Threads Chapter 4.
CHAPTER 4:THreads Bashair Al-harthi OPERATING SYSTEM
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Still Chapter 2 (Based on Silberchatz’s text and Nachos Roadmap.)
Chapter 4: Threads.
Lecture 10: Threads Implementation
Presentation transcript:

Chapter 4 Threads

Outline Definition of Thread Benefits of multithreading Thread Implementation User-level vs. Kernel-level Threads

Process Resource ownership Scheduling/execution follows an execution path that may be interleaved with other processes These two characteristics are treated independently by the operating system

Resource Ownership A virtual address space which holds the process image Protected access to processors, other processes (for interprocess communication), files, and I/O resources

One or More Threads in Process An execution state (running, ready, etc.) Saved thread context when not running An execution stack Access to the memory and resources of its process all threads of a process share this

Multithreading To support multiple, concurrent paths of execution within a single process Windows, Solaris, Linux, and Mac OS X support multiple processes and multiple threads per process

Single Threaded and Multithreaded Process Models

Advantages of Multithreading Similar to the advantages we can gain with cooperating processes Information sharing Modular program structure Speed of execution Convenience

Benefits of Threads Takes less time to create a new thread than a process Experiment shows that it is more than 10 times faster Less time to terminate a thread than a process Less time to switch between two threads within the same process

Benefits of Threads Since threads within the same process share memory and files, they can communicate with each other without the kernel’s involvement

Threads Suspending a process involves suspending all threads of the process since all threads share the same address space Termination of a process terminates all threads within the process

Thread Implementation - Packages Threads are provided as a package, including operations to create, destroy, and synchronize them A package can be implemented as: User-level threads Kernel threads

User-Level Threads All thread management is done by the application The kernel is not aware of the existence of threads

User-Level Threads

User-Level Threads Thread library entirely executed in user mode Kernel is not involved! Cheap to manage threads (e.g., Create: setup a stack & Destroy: free up memory) Cheap to do context switch (i.e., Just save CPU registers & Done based on program logic) However, a blocking system call blocks all peer threads

Kernel-Level Threads Kernel is aware of and schedules threads A blocking system call, will not block all peer threads Kernel maintains context information for the process and the threads Scheduling is done on a thread basis

Kernel-Level Threads

Kernel-Level Threads Kernel is aware of and schedules threads A blocking system call, will not block all peer threads More expensive to manage threads More expensive to do context switch Kernel intervention, mode switches are required

Thread/Process Operation Latencies user-level threads kernel-level threads processes fork 34 usec 948 usec 11,300 usec signal-wait 37 usec 441 usec 1,840 usec Experiments on a uniprocessor computer.

User vs. Kernel-Level Threads Users-level threads Cheap to manage and to do context switch A blocking system call blocks all peer threads Kernel-level threads A blocking system call will not block all peer threads Expensive to manage and to do context switch

Light-Weight Processes (LWP) Support for hybrid (user-level and kernel) threads, example is Solaris A process contains several LWPs In addition, the system provides user-level threads Developer: creates multi-threaded applications System: Maps threads to LWPs for execution

Thread Implementation – LWP Combining kernel-level lightweight processes and user-level threads

Thread Implementation – LWP Each LWP offers a virtual CPU LWPs are created by system calls They all run the scheduler, to schedule a thread Thread table is kept in user space Thread table is shard by all LWPs LWPs switch context between threads

Thread Implementation – LWP When a thread blocks for a signal from another thread, LWP schedules another ready thread Thread context switch is completely done in user mode When a thread blocks for I/O, the current LWP can no longer execute, context is switched to another LWP

LWP Features (I) Cheap thread management A blocking system call may not suspend the whole process

LWP Features (II) LWPs are transparent to the application LWPs can be easily mapped to different CPUs Managing LWPs is expensive (like kernel threads)

Thread Libraries Thread library provides programmer with API for creating and managing threads Two primary ways of implementing Library entirely in user space Kernel-level library supported by the OS

Pthreads A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization Specification, not implementation API specifies behavior of the thread library, implementation is up to development of the library May be provided either as user-level or kernel-level Common in UNIX operating systems (Solaris, Linux, Mac OS X) Modern Linux implementation of pthreads (i.e., NPTL) uses a 1:1 mapping between pthreads threads and kernel threads, so you get a kernel-level thread with pthread_create() http://en.wikipedia.org/wiki/Native_POSIX_Thread_Library

Pthreads Example

Pthreads Example (Cont.)

Appendix

(b) I/0 issued by thread 2, process B is blocked as a result (b) I/0 issued by thread 2, process B is blocked as a result. Thread 2 is not actually running in the sense of being executed on a processor; but it is perceived as being in the running state by the threads library. (d) Thread 2 blocked for an action by thread 1.