ThreadsThreads operating systems. ThreadsThreads A Thread, or thread of execution, is the sequence of instructions being executed. A process may have.

Slides:



Advertisements
Similar presentations
OPERATING SYSTEMS Threads
Advertisements

Chap 4 Multithreaded Programming. Thread A thread is a basic unit of CPU utilization It comprises a thread ID, a program counter, a register set and a.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Threads. Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems.
Threads.
Chapter 4: Multithreaded Programming
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
3.5 Interprocess Communication
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Thread definitions and relationship to process Multithreading.
Process Concept An operating system executes a variety of programs
Chapter 4: Threads READ 4.1 & 4.2 NOT RESPONSIBLE FOR 4.3 &
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
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.
9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
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.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Multithreaded Programming Overview.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 4 Operating Systems.
Chapter 4: Threads. 4.2 Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 4: Threads Modified from the slides of the text book. TY, Sept 2010.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
1 OS Review Processes and Threads Chi Zhang
Saurav Karmakar. Chapter 4: Threads  Overview  Multithreading Models  Thread Libraries  Threading Issues  Operating System Examples  Windows XP.
Operating System Concepts
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Threads prepared and instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University 1July 2016Processes.
Threads Overview Benefits, User and Kernel Threads.
Introduction to threads
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 4: Threads.
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 5: Threads Overview Multithreading Models(多线程模型)
Chapter 4: Multithreaded Programming
Chapter 4: Multithreaded Programming
Chapter 4 Threads.
Nadeem MajeedChoudhary.
Chapter 4: Threads.
Threads & multithreading
Operating System Concepts
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 4: Threads.
OPERATING SYSTEMS Threads
Lecture 10: Threads Implementation
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Lecture 10: Threads Implementation
Chapter 4: Threads.
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
CS Introduction to Operating Systems
Presentation transcript:

ThreadsThreads operating systems

ThreadsThreads A Thread, or thread of execution, is the sequence of instructions being executed. A process may have one or more threads. Each thread has its own * program counter * set of registers * execution stack But, all threads within a process share the same address space the same files, the same signals, and the same child processes! operating systems

codedatafilesregistersstack thread single thread process codedatafilesregistersstack thread registersstack thread multiple thread process pc

Why Threads? It allows an application to do multiple things at once * Real parallelism with multiple cpu’s * overlap I/O, user interaction with processing * share the same address space Threads are cheaper than processes because they have no resources associated with them. Context switches are cheaper. operating systems

Benefits of using threads Responsiveness: One thread can run while another is blocked * Resource sharing Economy: On a Solaris (SUN) O/S Thread creation is 30 times faster than process creation Context switching for a thread is 5 times faster than process context switching Exploitation of multi-processor architectures * Assuming that threads are implemented in the kernel operating systems

Implementing Threads There are two approaches to implementing threads, and the differences are quite controversial. Support for threads can be provided either at the user level or by the kernel. Virtually all contemporary operating systems support kernel threads. operating systems

Implementing Threads Implementing Threads in User Space user space kernel space process table thread table run-time system process threads thread table run-time system process threads A run-time system provides the interface to manage threads Each process has it’s own thread table No trap to kernel space is needed, no context switch is needed operating systems -- many to One Model --

Implementing Threads Implementing Threads in User Space user space kernel space process table thread table run-time system process threads thread table run-time system process threads operating systems Problems: 1. A blocking system call issued in one thread will block all threads in the process. 2. If a page fault occurs in one thread, all threads are blocked while the system pages. 3. Once a thread starts running there is no way to interrupt it. It must give up the cpu voluntarily.

Implementing Threads Implementing Threads in the Kernel user space kernel space process table process threads process threads No run time system. Use kernel calls to manage threads Thread table is kept in the kernel Kernel schedules threads, no blocking issues But … system calls are much more expensive than using a run-time system. thread table operating systems -- one to one model --

Implementing Threads There is a hybrid approach to thread support used by Linux. user space kernel space process table process threads process threads The kernel has a small set of re-usable threads that it manages. Threads in user space are mapped onto one of the available kernel threads. thread table run-time system thread table run-time system operating systems

Thread Libraries Thread libraries provide the programming interface for creating and managing threads. Thread libraries may be implemented completely in user space, or in kernel space.

Thread Libraries There are three main thread libraries in use today * POSIX pthreads * win32 threads * Java threads

Thread Issues When a thread issues a fork( ) system call, does the new process contain just one thread, or all of the threads of the original process?

Thread Issues When a signal occurs, should the signal * be delivered to all threads in the process? * deliver the signal only to the thread to which it applies? * deliver the signal to certain threads in the process? * Assign a specific thread to handle all signals for the process?