Department of Computer Science and Software Engineering

Slides:



Advertisements
Similar presentations
Threads, SMP, and Microkernels
Advertisements

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.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
Chapter 4: Multithreaded Programming
Chapter 5 Threads os5.
Computer Systems/Operating Systems - Class 8
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 7 Chapter 4: Threads (cont)
Day 10 Threads. Threads and Processes  Process is seen as two entities Unit of resource allocation (process or task) Unit of dispatch or scheduling (thread.
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples.
3.5 Interprocess Communication
Threads CSCI 444/544 Operating Systems Fall 2008.
1 Chapter 4 Threads Threads: Resource ownership and execution.
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
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 READ 4.1 & 4.2 NOT RESPONSIBLE FOR 4.3 &
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Operating System Principles Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
Chapter 4: Threads. From Processes to Threads 4.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Threads.
Thread. A basic unit of CPU utilization. It comprises a thread ID, a program counter, a register set, and a stack. It is a single sequential flow of control.
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.
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.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Operating System Concepts Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
1 Threads, SMP, and Microkernels Chapter Multithreading Operating system supports multiple threads of execution within a single process MS-DOS.
1 Lecture 4: Threads Advanced Operating System Fall 2010.
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.
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.
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.
Thread By Group III Kathryn Bean and Wafa’ Jaffal.
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
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution-
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Lecture 5. Example for periority The average waiting time : = 41/5= 8.2.
Threads Overview Benefits, User and Kernel Threads.
OPERATING SYSTEM CONCEPT AND PRACTISE
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 4 Threads.
Threads & multithreading
Lecture 4- Threads, SMP, and Microkernels
Chapter 4: Threads.
Presentation transcript:

Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-2 Threads Department of Computer Science and Software Engineering University of Wisconsin-Platteville

Outlines Process Aspects process vs. Threads Multithreading Process User and Kernel Threads Thread Pool

Process Aspects Process can be viewed two ways unit of resource ownership address space, containing program code and data open files, may be using an I/O device unit of scheduling execution path that may be interleaved with other processes These two aspects are treated independently by the operating system process = unit of resource ownership thread = unit of scheduling Operating system supports multiple threads of execution within a single process

Process vs. Thread Process Thread A process is a multithread where address space, program code, global variables, heap, OS resources : files, I/O devices Thread is a single sequential execution stream within a process A process is a multithread where Each thread has its own (other threads can access but shouldn’t) registers, program counter (PC) , stack, stack pointer (SP) All threads shares process resources Threads executes concurrently Each thread can block, fork, terminate, synchronize

Process Types

Multithreading Process: When Programs require multithreading programs with multiple independent tasks to provide quick user-response while carrying out main task server which needs to process multiple independent requests simultaneously OS kernel repetitive numerical tasks — break large problem down into small problems and assign each one to a separate thread programs difficult to multithread: programs that don’t have multiple concurrent tasks multi-task programs that require protection between tasks

Benefits of Threads Takes less time to create a new thread than a process Less time to terminate a thread than a process Less time to switch between two threads within the same process Since threads within the same process share memory and files, they can communicate with each other without invoking the kernel

Thread Termination Suspending a process involves suspending all threads of the process all process threads share the same address space Termination of a process, terminates all threads within the process

Thread States States associated with a change in thread state Spawn Spawn another thread Block Unblock Finish De-allocate register context and stacks

Thread States Example: Remote Procedure Call (RPC) Using Threads

Thread Types User-Level Threads Kernel-Level Threads

User-Level Threads provide a library of functions to allow user processes to manage (create, delete, schedule) their own threads OS is not aware of threads advantages: doesn’t require modification to the OS simple representation — each thread is represented simply by a PC, registers, stack, and a small control block, all stored in the user process’ address space simple management — creating a new thread, switching between threads, and synchronization between threads can all be done without intervention of the kernel fast — thread switching is not much more expensive than a procedure call flexible — CPU scheduling (among those threads) can be customized to suit the needs of the algorithm

User-Level Threads disadvantages: lack of coordination between threads and OS kernel process as a whole gets one time slice same time slice, whether process has 1 thread or 1000 threads also — up to each thread to relinquish control to other threads in that process requires non-blocking system calls otherwise, entire process will blocked in the kernel, even if there are runnable threads left in the process

Kernel-Level Threads kernel provides system calls to create and manage threads advantages kernel has full knowledge of all threads - scheduler may choose to give a process with 10 threads more time than process with only 1 thread good for applications that frequently block (e.g., server processes with frequent interprocess communication) disadvantages: slower — thread operations are significantly slower than for user-level threads significant overhead and increased kernel complexity — kernel must manage and schedule threads as well as processes - requires a full thread (task) control block (TCB) for each thread

Multithreading Models Many-to-One (Solaris’ green threads) – all user threads are mapped to one kernel thread: same problems as with user threads One-to-One (Windows XP, OS/2) – one user thread to one kernel thread programmer has better control of concurrency does not block the process on one thread blocking may potentially waste resources Many-to-Many – multiplexes many user-level threads to a smaller or equal number of kernel-level threads allocation is specific to a particular machine (more k. threads may be allocated on a multiprocessor)

Multithreading Models

Thread Pools threads may not be created infinitely – overwhelm computer resources consider web-server on-demand thread creation may not be fast enough thread pool create a number of threads in a pool where they remain blocked until activated activate when request arrives if more requests than threads – extra requests have to wait performance controllable process size fast response until pool exhausted

Thread APIs POSIX threads (pthreads) Win32 threads Java threads A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization Common in UNIX operating systems (Solaris, Linux, MacOS X) implemented on top of “native” OS threads or as a user-level package Win32 threads one-to-one mapping implemented on Windows OSes Java threads specified as part of Java maintained by JVM implemented on native threads or as a user-level package