Chapter 4 Threads Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.

Slides:



Advertisements
Similar presentations
Threads Chapter 4 Threads are a subdivision of processes
Advertisements

Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Threads, SMP, and Microkernels
Operating Systems: Internals and Design Principles
Chapter 3 Process Description and Control
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
Computer Systems/Operating Systems - Class 8
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.
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,
1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.
Threads Clients Servers Code Migration Software Agents Summary
Threads - Definition - Advantages using Threads - User and Kernel Threads - Multithreading Models - Java and Solaris Threads - Examples - Definition -
1 Chapter 4 Threads Threads: Resource ownership and execution.
Threads, SMP, and Microkernels
Inter-Process Communication  most OSs provide several abstractions for inter- process communication: message passing, shared memory, etc.  communication.
Threads. Processes and Threads  Two characteristics of “processes” as considered so far: Unit of resource allocation Unit of dispatch  Characteristics.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Threads Chapter 4. Modern Process & Thread –Process is an infrastructure in which execution takes place  (address space + resources) –Thread is a program.
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.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Operating Systems Lecture 09: Threads (Chapter 4)
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Threads, SMP, and Microkernels Chapter 4. 2 Outline n Threads n Symmetric Multiprocessing (SMP) n Microkernel n Linux Threads.
Chapter 3 Process Description and Control Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Operating System 4 THREADS, SMP AND MICROKERNELS
Threads, Thread management & Resource Management.
Chapter 4 Threads, SMP, and Microkernels Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design.
1 Threads, SMP, and Microkernels Chapter 4. 2 Focus and Subtopics Focus: More advanced concepts related to process management : Resource ownership vs.
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-
Threads G.Anuradha (Reference : William Stallings)
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership: process includes a virtual address space to hold the process image (fig 3.16)
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.
Threads, SMP, and Microkernels Chapter 4. Threads, SMP, and Microkernels 1. Processes and threads 2. Symmetric MultiProcessing (SMP) 3. Microkernel: structuring.
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.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
Department of Computer Science and Software Engineering
Thread By Group III Kathryn Bean and Wafa’ Jaffal.
Chapter 4 Threads Seventh Edition By William Stallings Operating Systems: Internals and Design Principles.
Operating Systems: Internals and Design Principles
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Module 2.0: Threads.
Threads, Thread management & Resource Management.
Chapter 4 Threads, SMP, and Microkernels Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution-
Threads, SMP and Microkernels Process vs. thread: –Unit of resource ownership (process has virtual address space, memory, I/O channels, files) –Unit of.
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
Processes Chapter 3. Processes in Distributed Systems Processes and threads –Introduction to threads –Distinction between threads and processes Threads.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Chapter 4 Threads.
Threads & multithreading
Operating System Concepts
Operating Systems Processes and Threads.
Threads, SMP, and Microkernels
Lecture 10: Threads Implementation
Threads Chapter 4.
Lecture 4- Threads, SMP, and Microkernels
Threads and Concurrency
Threads Chapter 4.
Chapter 4 Threads, SMP, and Microkernels
Lecture 10: Threads Implementation
Presentation transcript:

Chapter 4 Threads Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings

Processes and Threads Resource ownership - process includes a virtual address space to hold the process image Scheduling/execution- follows an execution path that may be interleaved with other processes These two characteristics are treated independently by the operating system

Processes and Threads Dispatching is referred to as a thread or lightweight process Resource ownership is referred to as a process or task

Multithreading To support multiple, concurrent paths of execution within a single process

Multithreading MS-DOS supports a single user process and thread Some variants of UNIX support multiple user processes but only one thread per process Java run-time environment is a single process with multiple threads Windows, Solaris, and other modern versions of Unix support multiple processes and multiple threads per process

Threads and Processes

Processes A virtual address space which holds the process image Protected access to processors, other processes (for interprocess communication), files, and I/O resources

One or More Threads in Process An execution state (running, ready, etc.) Saved thread context when not running An execution stack

One or More Threads in Process Some per-thread static storage for local variables Access to the memory and resources of its process –all threads of a process share this

Threads

Uses of Threads in a Single- User Multiprocessing System Modular program structure Foreground and background work –One thread for user-interface, another for data processing Speed of execution Asynchronous processing –For example, a thread to do backup for a word processor

Remote Procedure Call Using Single Thread Download and display a web page in a web browser

RPC Using One Thread per Server

Benefits of Threads Takes less time to create a new thread than a process –Experiment shows that it is 10 times faster Less time to terminate a thread than a process Less time to switch between two threads within the same process –No memory reallocation is involved

Benefits of Threads Since threads within the same process share memory and files, they can communicate with each other without invoking the kernel

Threads Suspending a process involves suspending all threads of the process since all 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 Deallocate register context and stacks

Thread Implementation - Packages Threads are provided as a package, including operations to create, destroy, and synchronize them A package can be implemented as: –User-level threads –Kernel threads

User-Level Threads All thread management is done by the application The kernel is not aware of the existence of threads

User-Level Threads

Thread library entirely executed in user mode Kernel is not involved! Cheap to manage threads –Create: setup a stack –Destroy: free up memory Cheap to do context switch –Just save CPU registers –Done based on program logic A blocking system call blocks all peer threads

Kernel-Level Threads Kernel is aware of and schedules threads A blocking system call, will not block all peer threads Windows is an example of this approach Kernel maintains context information for the process and the threads Scheduling is done on a thread basis

Kernel-Level Threads

Kernel is aware of and schedules threads A blocking system call, will not block all peer threads More expensive to manage threads More expensive to do context switch Kernel intervention, mode switches are required

Thread/Process Operation Latencies Operation user-level threadskernel-level threads processes null fork 34 usec ,300 usec usec signal-wait 37 usec441 usec1,840 usec

User vs. Kernel-Level Threads Users-level threads –Cheap to manage and to do context switch –A blocking system call blocks all peer threads Kernel-level threads –A blocking system call will not block all peer threads –Expensive to manage and to do context switch

Light-Weight Processes (LWP) Support for hybrid (user-level and kernel) threads, example is Solaris A process contains several LWPs In addition, the system provides user-level threads Developer: creates multi-threaded applications System: Maps threads to LWPs for execution

Thread Implementation – LWP Combining kernel-level lightweight processes and user- level threads

Thread Implementation – LWP Each LWP offers a virtual CPU LWPs are created by system calls They all run the scheduler, to schedule a thread Thread table is kept in user space Thread table is shard by all LWPs LWPs switch context between threads

Thread Implementation – LWP When a thread blocks, LWP schedules another ready thread Thread context switch is completely done in user mode When a thread blocks on a system call, execution mode changes from user to kernel but continues in the context of the current LWP When current LWP can no longer execute, context is switched to another LWP

Thread Implementation – LWP Combining kernel-level lightweight processes and user- level threads

LWP Features Cheap thread management A blocking system call may not suspend the whole process LWPs are transparent to the application LWPs can be easily mapped to different CPUs Managing LWPs is expensive (like kernel threads)

A Short Survey On awareness of CSE Bits & Bytes