EECE.4810/EECE.5730 Operating Systems

Slides:



Advertisements
Similar presentations
Threads Relation to processes Threads exist as subsets of processes Threads share memory and state information within a process Switching between threads.
Advertisements

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 4: Threads CS 170 TY, Sept 2011.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Process Concept An operating system executes a variety of programs
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Chapter 4: Threads Adapted to COP4610 by Robert van Engelen.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
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 CS 170 T Yang, Sept 2012.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads Changes by MA Doman 2013.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Threads A thread (or lightweight process) is a basic unit of CPU.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
PRINCIPLES OF OPERATING SYSTEMS Lecture 6: Processes CPSC 457, Spring 2015 May 21, 2015 M. Reza Zakerinasab Department of Computer Science, University.
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.
Professor: Shu-Ching Chen TA: Samira Pouyanfar.  An independent stream of instructions that can be scheduled to run  A path of execution int a, b; int.
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.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Threads. Readings r Silberschatz et al : Chapter 4.
NCHU System & Network Lab Lab #6 Thread Management Operating System Lab.
Thread Basic Thread operations include thread creation, termination, synchronization, data management Threads in the same process share:  Process address.
PRINCIPLES OF OPERATING SYSTEMS Tutorial-4: Multi-process and Multi-threaded Programming CPSC 457, Spring 2015 May 28/29, 2015 Department of Computer Science,
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
B. RAMAMURTHY 5/10/2013 Amrita-UB-MSES Realizing Concurrency using the thread model.
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Multithreaded Programming.
Chapter 4 – Thread Concepts
Realizing Concurrency using the thread model
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
Realizing Concurrency using the thread model
Day 12 Threads.
Chapter 4 – Thread Concepts
CS399 New Beginnings Jonathan Walpole.
Multithreading Tutorial
Realizing Concurrency using Posix Threads (pthreads)
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
Realizing Concurrency using the thread model
Multithreading Tutorial
Realizing Concurrency using the thread model
Multithreading Tutorial
EECE.4810/EECE.5730 Operating Systems
Multithreading Tutorial
Realizing Concurrency using the thread model
Realizing Concurrency using Posix Threads (pthreads)
Realizing Concurrency using the thread model
Realizing Concurrency using Posix Threads (pthreads)
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
EECE.3170 Microprocessor Systems Design I
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
Presentation transcript:

EECE.4810/EECE.5730 Operating Systems Instructor: Dr. Michael Geiger Spring 2019 Lecture 9: Threads

Operating Systems: Lecture 8 Lecture outline Announcements/reminders Program 1 due today Write one program that does everything Objective list is an outline that could be used to guide development, but feel free to skip steps If wait() returns -1, called from process without child! Please respond to the exam scheduling poll Today’s lecture Review: multithreading basics Continue threading discussion Pthread example programs 8/26/2019 Operating Systems: Lecture 8

Operating Systems: Lecture 6 Review: Threads Thread: active sequence of instructions Basic unit of CPU utilization Thread creation is lightweight Multiple threads in same process can share address space Each thread needs own PC, register copies, stack + SP Threads provide concurrency within application HW support necessary for parallelism Major issue: non-deterministic ordering Solutions require atomic operations Avoid race condition: solution depends on timing/ordering of earlier events 8/26/2019 Operating Systems: Lecture 6

Operating Systems: Lecture 8 Example Thread A Thread B i = 0 i = 0 while (i < 10) while (i > -10) i++ i-- print “A done” print “B done” Which thread finishes first? Is winner guaranteed to print first? Is it guaranteed that one thread will win? What’s required to guarantee one thread will win? 8/26/2019 Operating Systems: Lecture 8

Multithreaded debugging Non-deterministic ordering makes debugging difficult “Heisenbug”: bug that occurs non-deterministically All possible interleavings must be correct Race condition: output/result dependent on timing or ordering of earlier events Becomes bug when unanticipated ordering occurs Potentially disastrous consequences Over-radiation in Therac-25 2 modes of operation: direct low-power radiation, high-powered radiation + safeguards Race condition activated high-powered beam w/o safeguards Northeast blackout of 2003 Race condition in control software 8/26/2019 Operating Systems: Lecture 8

Operating Systems: Lecture 8 Synchronization Constrain interleavings between threads Goal: force all possible interleavings to produce correct result Correct concurrent program should work regardless of processor speed Try to constrain as little as possible Some events are independent—order irrelevant Order only matters in dependent events Synchronization: Controlling execution and order of threads 8/26/2019 Operating Systems: Lecture 8

Operating Systems: Lecture 6 Pthreads POSIX thread API (Pthreads) supported on most systems Necessary functions included in <pthread.h> Files may need to be compiled with –pthread or –lpthread option Library contains functions for: Thread creation and termination Thread joining (forced waiting  simple synch) Synchronization (locks, condition variables, barriers) Other thread management 8/26/2019 Operating Systems: Lecture 6

Operating Systems: Lecture 6 Pthread examples Three example programs Functions covered pthread_create(thread, attr, start_routine, arg) pthread_exit(status) pthread_join(thread, status) 8/26/2019 Operating Systems: Lecture 6

Operating Systems: Lecture 8 Final notes Next time Detailed synchronization discussion Reminders: Program 1 due today Write one program that does everything Objective list is an outline that could be used to guide development, but feel free to skip steps If wait() returns -1, called from process without child! 8/26/2019 Operating Systems: Lecture 8

Operating Systems: Lecture 8 Acknowledgements These slides are adapted from the following sources: Silberschatz, Galvin, & Gagne, Operating Systems Concepts, 9th edition Chen & Madhyastha, EECS 482 lecture notes, University of Michigan, Fall 2016 8/26/2019 Operating Systems: Lecture 8