Threads David Ferry CSCI 3500 – Operating Systems

Slides:



Advertisements
Similar presentations
Threads. Readings r Silberschatz et al : Chapter 4.
Advertisements

CHAPTER 5 THREADS & MULTITHREADING 1. Single and Multithreaded Processes 2.
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
Threads vs. Processes April 7, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
CS 3013 & CS 502 Summer 2006 Threads1 CS-3013 & CS-502 Summer 2006.
Processes Part I Processes & Threads* *Referred to slides by Dr. Sanjeev Setia at George Mason University Chapter 3.
1 From Processes to Threads. 2 Processes, Threads and Processors Hardware can interpret N instruction streams at once  Uniprocessor, N==1  Dual-core,
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Threads, Thread management & Resource Management.
E X C E E D I N G E X P E C T A T I O N S OP SYS Linux System Administration Dr. Hoganson Kennesaw State University Operating Systems Functions of an operating.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
Operating Systems and Systems Programming CS162 Teaching Staff.
CS333 Intro to Operating Systems Jonathan Walpole.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
Processes & Threads Introduction to Operating Systems: Module 5.
1 OS Review Processes and Threads Chi Zhang
CSC 360, Instructor: Kui Wu Thread & PThread. CSC 360, Instructor: Kui Wu Agenda 1.What is thread? 2.User vs kernel threads 3.Thread models 4.Thread issues.
Threads. Readings r Silberschatz et al : Chapter 4.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
2.2 Threads  Process: address space + code execution  There is no law that states that a process cannot have more than one “line” of execution.  Threads:
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Threads prepared and instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University 1July 2016Processes.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Threads Overview Benefits, User and Kernel Threads.
Introduction to threads
Process Management Process Concept Why only the global variables?
CS 6560: Operating Systems Design
CSCI 511 Operating Systems Ch3, 4 (Part C) Cooperating Threads
Operating Systems (CS 340 D)
Processes and Threads Processes and their scheduling
OPERATING SYSTEMS CS3502 Fall 2017
Lecture Topics: 11/1 Processes Process Management
Threads in C Caryl Rahn.
CS399 New Beginnings Jonathan Walpole.
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Operating System (013022) Dr. H. Iwidat
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 4 Threads.
Operating Systems Threads.
Threads & multithreading
Chapter 4: Threads.
Operating System Concepts
Operating Systems and Systems Programming
CSCI 511 Operating Systems Ch3, 4 (Part C) Cooperating Threads
ICS 143 Principles of Operating Systems
Chapter 4: Threads.
Process & its States Lecture 5.
CS510 Operating System Foundations
PROCESS MANAGEMENT Information maintained by OS for process management
Lecture Topics: 11/1 General Operating System Concepts Processes
Operating System Concepts
CHAPTER 4:THreads Bashair Al-harthi OPERATING SYSTEM
Multithreaded Programming
Processes and Process Management
Introduction to Operating Systems
Jonathan Walpole Computer Science Portland State University
Prof. Leonardo Mostarda University of Camerino
PROCESSES & THREADS ADINA-CLAUDIA STOICA.
Processes David Ferry CSCI 3500 – Operating Systems
Race Conditions David Ferry CSCI 3500 – Operating Systems
Threads vs. Processes Hank Levy 1.
Chapter 3: Processes Process Concept Process Scheduling
Threads CSE 2431: Introduction to Operating Systems
CS Introduction to Operating Systems
Presentation transcript:

Threads David Ferry CSCI 3500 – Operating Systems Saint Louis University St. Louis, MO 63103

CSCI 3500 - Operating Systems Processes vs. Threads Process – a program in execution Every process has at least one thread Comprehensive abstraction for execution Tracks memory usage, files opened, etc. Thread – an execution context A processor state (register file and program counter) plus a stack Everything needed for the fetch, decode, execute cycle Belong to a specific process, share resources May have many threads per process Lighter weight and faster to create/deploy/destroy CSCI 3500 - Operating Systems

CSCI 3500 - Operating Systems Single Thread Model Process Control Block (PCB) .stack Memory Map Open Files Accounting Info Program Counter Register File Etc. .heap .data .text CSCI 3500 - Operating Systems

Multiple Threads Model Process Control Block (PCB) .stack Memory Map Open Files Accounting Info Program Counter Register File Etc. .stack .stack .heap .data .text Register file contains stack pointers. Creating a thread does not need new PCB CSCI 3500 - Operating Systems

CSCI 3500 - Operating Systems Why use threads? In parallel computing the goal is to accelerate computations Split one large piece of work across multiple threads, and execute on multiple processors In concurrent programming threads provide: Separation of concerns Latency hiding for blocking I/O CSCI 3500 - Operating Systems

Concurrency: Separation of Concerns Sequential computing often introduces accidental complexity – unintended interactions between different program elements. main(){ functionA(); functionB(); functionC(); } If functions A, B, and C do not interact with one another, then their sequential dependence is accidental. If functionB() hangs, then functionC() is impacted. CSCI 3500 - Operating Systems

Concurrency: Separation of Concerns Consider a simple game structure: while(1){ play_sound(); do_physics(); draw_graphics(); } A bug or hang in any of these functions impacts the others. Suppose a sound or image loads slowly from disk Putting each of these in a thread allows each to progress at their own rate. Behavior of the overall program is decoupled from the progress of any individual part. Adds complexity where these pieces interact CSCI 3500 - Operating Systems

Concurrency: Hiding I/O and Blocking Latency Suppose we have two independent but I/O-heavy compute routines: main(){ computeA(); computeB(); } Calls such as file access may take a while to complete, or may block entirely. In the above structure all such delays contribute to program runtime. If these functions are threaded then one can execute while the other is blocked. Even if we only have one physical processor. CSCI 3500 - Operating Systems

Early Threading Success: Web Servers Studies show internet users are impatient. A goal of web companies is to minimize the time it takes to get your page. Suppose you are a web search provider, and some searches are fast (e.g. cached), while other searches are slow. How do we minimize latency for fast requests? Request Queue (First-In, First-Out) Web Server CSCI 3500 - Operating Systems

Multithreaded Web Server Suppose the web server has a team of threads that it switches between rapidly (i.e. multiprogramming). Slow requests take longer Fast requests much less likely to get stuck after a slow request Works even if we only have one processor. Web Server Request Queue (First-In, First-Out) CSCI 3500 - Operating Systems

CSCI 3500 - Operating Systems pthreads Interface pthreads (POSIX threads) is a cross-platform library for threading and thread management. Very much a C-style interface- no OOP so no thread objects. No type polymorphism, instead we use void* (typeless) pointers and it’s up to the programmer to ensure correctness. Uses a function pointer to determine where thread starts executing. pthread_create( pthread_t*, NULL, (void*)*(void*), void*) pthread_join( pthread_t, void**) See documentation/studios/examples for details… CSCI 3500 - Operating Systems