Threads vs. Processes Hank Levy 1.

Slides:



Advertisements
Similar presentations
Operating Systems COMP 4850/CISG 5550 Processes Introduction to Threads Dr. James Money.
Advertisements

Operating Systems ECE344 Lecture 4: Threads Ding Yuan.
Processes and Threads Prof. Sirer CS 4410 Cornell University.
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.
Threads. Announcements Cooperating Processes Last time we discussed how processes can be independent or work cooperatively Cooperating processes can.
Scheduler Activations Effective Kernel Support for the User-Level Management of Parallelism.
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.
Threads. Announcements CSUGLab accounts are ready Fixed homework 1 submissions using CMS.
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Chapter 4: Threads.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
CS 153 Design of Operating Systems Spring 2015
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Threads, Thread management & Resource Management.
Threads and Concurrency. A First Look at Some Key Concepts kernel The software component that controls the hardware directly, and implements the core.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
CSE 451: Operating Systems Winter 2015 Module 5 1 / 2 User-Level Threads & Scheduler Activations Mark Zbikowski 476 Allen Center.
CSE 451: Operating Systems Winter 2014 Module 5 Threads Mark Zbikowski Allen Center 476 © 2013 Gribble, Lazowska, Levy, Zahorjan.
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.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Department of Computer Science and Software Engineering
CSE 153 Design of Operating Systems Winter 2015 Lecture 4: Threads.
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
Jonas Johansson Summarizing presentation of Scheduler Activations – A different approach to parallelism.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Processes and threads.
Process Management Process Concept Why only the global variables?
CS 6560: Operating Systems Design
CSE 120 Principles of Operating
CSE 451: Operating Systems Winter 2011 Threads
Processes and Threads Processes and their scheduling
Day 12 Threads.
CSE 451: Operating Systems Spring 2013 Module 5 Threads
Chapter 4: Multithreaded Programming
Chapter 4 Threads.
Operating Systems ECE344 Lecture 4: Threads Ding Yuan.
Threads & multithreading
Chapter 4: Threads.
Operating System Concepts
CSE 451: Operating Systems Winter 2010 Module 5 Threads
CSE 451: Operating Systems Winter 2007 Module 5 Threads
CSE 451: Operating Systems Autumn 2004 Module 5 Threads
CSE 410, Spring 2008 Computer Systems
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
CSE 451: Operating Systems Spring 2008 Module 5 Threads
CSE 153 Design of Operating Systems Winter 2018
Thread Implementation Issues
Lecture Topics: 11/1 General Operating System Concepts Processes
CSE 451: Operating Systems Autumn 2003 Lecture 5 Threads
Threads Chapter 4.
CSE 451: Operating Systems Winter 2007 Module 5 Threads
CSE 451: Operating Systems Winter 2003 Lecture 5 Threads
CSE 451: Operating Systems Winter 2009 Module 5 Threads
CSE 451: Operating Systems Spring 2005 Module 5 Threads
October 9, 2002 Gary Kimura Lecture #5 October 9, 2002
CSE 451: Operating Systems Winter 2012 Threads
CSE 451: Operating Systems Autumn 2009 Module 5 Threads
Thomas E. Anderson, Brian N. Bershad,
CS510 Operating System Foundations
CSE 153 Design of Operating Systems Winter 2019
CS703 – Advanced Operating Systems
CSE451 Introduction to Operating Systems Spring 2007
CSE 451: Operating Systems Winter 2006 Module 5 Threads
CSE 451: Operating Systems Winter 2001 Lecture 5 Threads
Threads.
CS Introduction to Operating Systems
Presentation transcript:

Threads vs. Processes Hank Levy 1

Processes and Threads A full process includes numerous things: an address space (defining all the code and data pages) OS resources and accounting information a “thread of control”, which defines where the process is currently executing (basically, the PC and registers) Creating a new process is costly, because of all of the structures (e.g., page tables) that must be allocated Communicating between processes is costly, because most communication goes through the OS

Parallel Programs Suppose I want to build a parallel program to execute on a multiprocessor, or a web server to handle multiple simultaneous web requests. I need to: create several processes that can execute in parallel cause each to map to the same address space (because they’re part of the same computation) give each its starting address and initial parameters the OS will then schedule these processes, in parallel, on the various processors Notice that there’s a lot of cost in creating these processes and possibly coordinating them. There’s also a lot of duplication, because they all share the same address space, protection, etc……

“Lightweight” Processes What’s similar in these processes? They all share the same code and data (address space) they all share the same privileges they share almost everything in the process What don’t they share? Each has its own PC, registers, and stack pointer Idea: why don’t we separate the idea of process (address space, accounting, etc.) from that of the minimal “thread of control” (PC, SP, registers)?

Threads and Processes Some newer operating systems (Mach, Chorus, NT) therefore support two entities: the process, which defines the address space and general process attributes the thread, which defines a sequential execution stream within a process A thread is bound to a single process. For each process, however, there may be many threads. Threads are the unit of scheduling; processes are containers in which threads execute.

How different OSs support threads = address space = thread example: MS/DOS example: Unix example: Xerox Pilot example: Mach, OSF, Chorus, NT

Separation of Threads and Processes Separating threads and processes makes it easier to support multi-threaded applications Concurrency (multi-threading) is useful for: improving program structure handling concurrent events (e.g., web requests) building parallel programs So, multi-threading is useful even on a uniprocessor. But, threads, even when supported separately from processes in the kernel, are too slow.

Kernel Threads Kernel threads still suffer from performance problems. Operations on kernel threads are slow because: a thread operation still requires a kernel call kernel threads may be overly general, in order to support needs of different users, languages, etc. the kernel doesn’t trust the user, so there must be lots of checking on kernel calls

User-Level Threads To make threads really fast, they should be implemented at the user level A user-level thread is managed entirely by the run-time system (user-level code that is linked with your program). Each thread is represented simply by a PC, registers, stack and a little control block, managed in the user’s address space. Creating a new thread, switching between threads, and synchronizing between threads can all be done without kernel involvement.

(Old) Example of thread performance (perf. on a 3 MIPs processor) Ultrix: 1 thread per address space Topaz: multiple threads per address space FastThreads: multiple user threads per address space

Example U-L Thread Interface t = thread_fork(initial context) create a new thread of control sometimes show as thread_create(), thread_setstate(initial context) thread_stop() stop the calling thread, sometimes called thread_block thread_start(t) start the named thread thread_yield() voluntarily give up the processor thread_exit() terminate the calling thread, somtimes called thread_destroy.

Key Data Structures your process address space your program: your data (shared by all your threads): for i (1, 10, I++) thread_fork(proc_x, i); …. queue of thread control blocks user-level thread code: proc thread_fork()… proc thread_block()… proc thread_exit()... per-thread stacks

User-Level Theads: Implementation Kernel processes kernel process ready queue U-L thread schedulers user thread ready queue current threads thread ready queue

Threads The OS is a huge multi-threaded program. Multi-threading is useful for applications as well. User-Level threads can be 100x faster than similar kernel thread operations. But user-level threads suffer from a problem of poor integration; because they’re invisible to the OS, the OS can make poor scheduling decisions, e.g.: running a process that has no work (is running an idle thread) blocking a process whose u-l thread has requested I/O, even though other threads can run in that process removing a process whose u-l thread is holding a lock Solving this requires communication between the kernel and the u-l thread manager.