Lecture 10: Threads Implementation

Slides:



Advertisements
Similar presentations
Chapter 4 Threads Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
Advertisements

Threads, SMP, and Microkernels
Threads Relation to processes Threads exist as subsets of processes Threads share memory and state information within a process Switching between threads.
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Threads CSCI 444/544 Operating Systems Fall 2008.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
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.
ThreadsThreads operating systems. ThreadsThreads A Thread, or thread of execution, is the sequence of instructions being executed. A process may have.
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.
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
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)
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.
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.
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.
Threads G.Anuradha (Reference : William Stallings)
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
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.
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.
Department of Computer Science and Software Engineering
Thread By Group III Kathryn Bean and Wafa’ Jaffal.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
CSC 322 Operating Systems Concepts Lecture - 7: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Cooperating Processes The concurrent processes executing in the operating system may be either independent processes or cooperating processes. A process.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution-
Threads, SMP and Microkernels Process vs. thread: –Unit of resource ownership (process has virtual address space, memory, I/O channels, files) –Unit of.
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Threads Overview Benefits, User and Kernel Threads.
OPERATING SYSTEM CONCEPT AND PRACTISE
CS 6560: Operating Systems Design
Day 12 Threads.
Concurrency, Processes and Threads
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 4: Threads.
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 4: Multithreaded Programming
Chapter 4 Threads.
Threads & multithreading
Operating System Concepts
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 4: Threads.
Operating System Concepts
Chapter 4: Threads.
Threads Chapter 4.
Lecture 4- Threads, SMP, and Microkernels
Threads and Concurrency
Threads Chapter 4.
Chapter 4: Threads.
Lecture 10: Threads Implementation
Lecture 11: Mutual Exclusion
Chapter 5: Threads Overview Multithreading Models Threading Issues
Concurrency, Processes and Threads
Chapter 4: Threads.
CS703 – Advanced Operating Systems
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

Lecture 10: Threads Implementation

Review: POSIX Standards pthread_create() pthread_exit() pthread_join() pthread_yield()

In this lecture Threads implementation User Level Threads Kernel Level Threads Hybrid Implementations

What is a Thread? Execution context Registers, Stack Shared text, heap, static data segments Thread execution context smaller than process execution context

User Space Threads All the thread support provided by a user level library Kernel not even aware that the program has multiple threads User library also handles synchronization (mutexes, condition variables, etc)

Implementing Threads in User Space A user-level threads package

Pros of User Space Implementation Can be used in OSes which don’t implement threads Thread related operations are fast (no system calls) creation Each process can have its own thread scheduling algorithm Thread scheduling is also faster

Cons of User Space Implementation System calls/page faults block and other threads will not be able to execute No benefits of multi-threading Possible solutions Change system calls to be nonblocking Wrap system calls. Check whether it is safe before making system calls

Implementing Threads in the Kernel A threads package managed by the kernel

Kernel Space Pros: Cons: Can take advantage of multiple processors System call/page fault blocks only the thread which made the call Cons: Thread operations involve system calls (expensive) Solution: recycle threads

Hybrid Implementations Multiplexing user-level threads onto kernel- level threads

Processes & Threads Resource ownership – Process or Task Scheduling/execution – Thread or lightweight process One process, one thread (MS-DOS) One process, multiple threads (Java Runtime) Multiple processes, one thread per process (Unix) Multiple processes, multiple threads (W2K, Solaris, Linux)

Single Threaded and Multithreaded Process Models

Key Benefits of Threads

User and Kernel-Level Threads Performance Null fork: the time to create, schedule, execute, and complete a process/thread that invokes the null procedure. Signal-Wait: the time for a process/thread to signal a waiting process/thread and then wait on a condition. Procedure call: 7us Kernel Trap:17us Thread Operation Latencies Operation ULT KLT Process Null fork 34 948 11,300 Signal Wait 37 441 1,840 Observation While there is a significant speedup by using KLT multithreading compared to single-threaded processes, there is an additional significant speedup by using ULTs. However, whether or not the additional speedup is realized depends on the nature of the applications involved. If most of the thread switches require kernel mode access, then ULT may not perform much better than KLT.