1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!

Slides:



Advertisements
Similar presentations
Why Concurrency? Allows multiple applications to run at the same time  Analogy: juggling.
Advertisements

1 SEDA: An Architecture for Well- Conditioned, Scalable Internet Services Matt Welsh, David Culler, and Eric Brewer Computer Science Division University.
Threads, Events, and Scheduling Andy Wang COP 5611 Advanced Operating Systems.
Operating Systems Parallel Systems (Now basic OS knowledge)
Threads Irfan Khan Myo Thein What Are Threads ? a light, fine, string like length of material made up of two or more fibers or strands of spun cotton,
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
Capriccio: Scalable Threads for Internet Services ( by Behren, Condit, Zhou, Necula, Brewer ) Presented by Alex Sherman and Sarita Bafna.
Operating Systems Parallel Systems and Threads (Soon to be basic OS knowledge)
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Dr. Mohamed Hefeeda.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
Threads vs. Processes April 7, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples.
OS Spring’03 Introduction Operating Systems Spring 2003.
Concurrency, Threads, and Events Robbert van Renesse.
CS533 Concepts of Operating Systems Class 3 Integrated Task and Stack Management.
CPS110: Implementing threads/locks on a uni-processor Landon Cox.
Why Threads Are A Bad Idea (for most purposes) John Ousterhout Sun Microsystems Laboratories
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
Cooperative Task Management without Manual Stack Management Or, Event-driven Programming is not the Opposite of Thread Programming Atul Adya, John Howell,
Advanced Operating Systems CIS 720 Lecture 1. Instructor Dr. Gurdip Singh – 234 Nichols Hall –
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Event Driven Programming
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Operating Systems Lecture 2 Processes and Threads Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
CS333 Intro to Operating Systems Jonathan Walpole.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
CSE 451: Operating Systems Winter 2015 Module 5 1 / 2 User-Level Threads & Scheduler Activations Mark Zbikowski 476 Allen Center.
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.
Introduction to Operating Systems and Concurrency.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Department of Computer Science and Software Engineering
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
CSE 60641: Operating Systems Next topic: CPU (Process/threads/scheduling, synchronization and deadlocks) –Why threads are a bad idea (for most purposes).
Processes & Threads Introduction to Operating Systems: Module 5.
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
Threads versus Events CSE451 Andrew Whitaker. This Class Threads vs. events is an ongoing debate  So, neat-and-tidy answers aren’t necessarily available.
CS533 - Concepts of Operating Systems 1 Threads, Events, and Reactive Objects - Alan West.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
Chapter 6 Limited Direct Execution Chien-Chung Shen CIS/UD
Processes Chapter 3. Processes in Distributed Systems Processes and threads –Introduction to threads –Distinction between threads and processes Threads.
Scheduler activations Landon Cox March 23, What is a process? Informal A program in execution Running code + things it can read/write Process ≠
Threads prepared and instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University 1July 2016Processes.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Introduction to Operating Systems Concepts
Processes and threads.
Advanced Operating Systems CIS 720
Scheduler activations
CS399 New Beginnings Jonathan Walpole.
Intro to Processes CSSE 332 Operating Systems
Threads, Events, and Scheduling
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Threads, Events, and Scheduling
Threads, Events, and Scheduling
Why Threads Are A Bad Idea (for most purposes)
Threads vs. Processes Hank Levy 1.
CS510 Operating System Foundations
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
Interrupts and System Calls
CS Introduction to Operating Systems
Presentation transcript:

1 Why Threads are a Bad Idea (for most purposes) based on a presentation by John Ousterhout Sun Microsystems Laboratories Threads!

2 Threads give us: multiple execution streams Threads! Concurrency during execution  OSes use a kernel thread per user process  big computations can be divided among separate threads  but there is only speed up if you have a CPU for each thread  if single processing system, no time gain, just gain a lot of context switches

3 Threads give us: multiple execution streams Threads! Concurrency during blocking  process an I/O request in a separate thread  then overlap I/Os  i.e., when the thread blocks, do other work in another thread  works great in GUIs too -- have a thread to handle user actions  even if only one CPU, this works

4 Threads give us: logical control flow Threads!  multiple threads, but each thread is a single flow of execution  if the thread blocks, and another gets scheduled (or not!), the blocked thread’s stack is intact  the thread is all set to resume when offered the chance  this is a very comfortable and familiar abstraction!

5 Threads give us: Threads! Let the argument begin! One side says:  Spawning threads is easy…  …synchronization, now that’s hard!

6 Threads give us: Threads!  shared storage must be protected  mutexes, semaphores, monitors (oh my!)  non-blocking strategies  Read-Copy-Update & Hazard Pointers (hazard?!?)  re-entrant functions and libraries  data races and deadlock  difficult to program, hard to debug (Eraser showed us that)  local lock round trip = instructions  and as we’ll see with SEDA -- poor scalability!

7 Threads give us: Threads! And the biggest disadvantage of threads: Concurrency whether you need it or not!  what if all you need is non-blocking I/O?  or fast GUI response time?  what if you only have one processor?  if you use threads, you have to suffer the slings and arrows of synchronization  lock acquisition, lock contention, context switches

8 Event Driven Design gives us: 1 thread! an opposite philosophy  ONLY ONE THREAD!  an application is interested in certain events  rather than give work to a thread, code and call an event-handler to handle each particular event  app registers interest in each event, which essentially means: “when this event occurs, call this event-handler”  the app tells the environment to inform it when something happens, then app reacts

event_driven_programming.html 9 Event Driven Design gives us: events  the Agent is usually is a set of library functions  registration is also a library call  the Agent runs an event loop, ‘sensing’ events  when an event occurs, the event loop makes a callback to the event handler

10 Event Driven Design gives us: control  event dispatch can be implemented in different ways, varying in complexity, for example:  simple polling for events in a case statement that invokes event handlers  an event table that stores event registrations; do a lookup on the table to find which handler to invoke  detected events get placed on an event queue for the event’s handler  the current state of event queues can be used to make scheduling decisions

11 Event Driven Design gives us: control  event queues give us control over which events are handled when  unlike threads, in which the thread scheduler is part of a threads package or part of the OS, with events, the application can control the scheduling of handling events  this control is a key element of scalability! (as we’ll see with SEDA)

12 Event Driven Design gives us: 1 issue!  BUT event-driven I/O is not so straightforward!  here is the other side of the argument  the initial invocation of the event handler CAN’T block!  Only 1 thread!  It must return!

13 + Bottom Line Threads!  if you don’t need concurrency, then use events  faster!  no locks  no context switches  easier to program  if you can and will use concurrency, then use threads!  e.g., multiple CPUs