Threads Chapter 5 2/17/2019 B.Ramamurthy.

Slides:



Advertisements
Similar presentations
OPERATING SYSTEMS Threads
Advertisements

Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows.
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP 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.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Chapter 4: Threads Overview Multithreading.
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 &
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.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
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.
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 ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter 1 Process and Thread. 1.2 process The address space of a program – Text – Code – Stack – Heap A set of registers – PC – SP Other resources – Files.
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 Lecture 4: Threads Advanced Operating System Fall 2010.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Threads Overview Multithreading Models Threading Issues.
Chapter 4: Threads. 2 Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads.
Overview Multithreading Models Threading Issues Pthreads Solaris 2 Threads Windows 2000 Threads Linux Threads Java Threads.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
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.
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.
1 OS Review Processes and Threads Chi Zhang
Operating System Concepts
CMSC 421 Spring 2004 Section 0202 Part II: Process Management Chapter 5 Threads.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 5: Threads Overview Multithreading Models(多线程模型)
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 4 Threads.
Nadeem MajeedChoudhary.
Chapter 4: Threads.
Nachos Threads and Concurrency
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 4: Threads.
OPERATING SYSTEMS Threads
Modified by H. Schulzrinne 02/15/10 Chapter 4: Threads.
Chapter 4: Threads.
Threads Chapter 4.
Chapter 4: Threads.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Still Chapter 2 (Based on Silberchatz’s text and Nachos Roadmap.)
Threads and Concurrency
Chapter 4: Threads.
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 4: Threads.
Chapter 4: Threads.
Chapter 4: Threads.
Presentation transcript:

Threads Chapter 5 2/17/2019 B.Ramamurthy

Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris 2 Threads Windows 2000 Threads Nachos Threads 2/17/2019 B.Ramamurthy

Single and Multithreaded Processes Thread specific Data (TSD) Code 2/17/2019 B.Ramamurthy

User Threads Thread management done by user-level threads library Examples - POSIX Pthreads - Solaris threads - Nachos Thread 2/17/2019 B.Ramamurthy

Kernel Threads Supported by the Kernel Examples - Windows 95/98/NT/2000 - Solaris - Tru64 UNIX - BeOS - Linux 2/17/2019 B.Ramamurthy

Thread Models Many to One: One to One Many to Many Many user-level threads mapped to single kernel thread. Used on systems that do not support kernel threads. One to One Each user-level thread maps to kernel thread. Examples - Windows 95/98/NT/2000 - OS/2 Many to Many 2/17/2019 B.Ramamurthy

Many-to-One Model 2/17/2019 B.Ramamurthy

One-to-one Model 2/17/2019 B.Ramamurthy

Many-to-Many Model Allows many user level threads to be mapped to many kernel threads. Allows the operating system to create a sufficient number of kernel threads. Solaris 2 Windows NT/2000 with the ThreadFiber package 2/17/2019 B.Ramamurthy

Many-to-Many Model 2/17/2019 B.Ramamurthy

Thread Thread Data Structures Thread control methods 2/17/2019 B.Ramamurthy

Threading Issues Thread life cycle management Thread specific data Thread create, thread suspend, thread yield, thread resume, thread sleep, thread kill, thread start, thread stop Thread specific data Thread pools Signal handling 2/17/2019 B.Ramamurthy

Pthreads a POSIX standard (IEEE 1003.1c) API for thread creation and synchronization. API specifies behavior of the thread library, implementation is up to development of the library. Common in UNIX operating systems. Simply a collection of C function. 2/17/2019 B.Ramamurthy

Solaris 2 Threads 2/17/2019 B.Ramamurthy

Solaris Process 2/17/2019 B.Ramamurthy

Nachos Thread Nachos process consists of An address space Executable code Stack space for automatic (local) variables Heap space for global variables A single thread of control Other object such as file descriptors We allow multiple threads of control to execute concurrently. 2/17/2019 B.Ramamurthy

Thread States JUST_CREATED READY RUNNING BLOCKED Thread() Fork() Scheduler dispatch Waiting for an event Event occurs BLOCKED 2/17/2019 B.Ramamurthy

Nachos Thread Operations Creation: Thread *Thread(char *debugName); Create a thread but no code attached yet. Fork (voidfunctionPtr func, int arg); Associate a function to be executed by the thread. Control: void Yield() Suspend the current thread (calling thread..self) and select a new one for execution from the Ready queue 2/17/2019 B.Ramamurthy

Nachos Thread Operation void Sleep() Suspend the current thread, change its state to BLOCKED; It will return to READY on when a particular event takes place. void Finish() Terminate current thread. Return all data structures held to the system; Finish sets the gloabal variable threadToBe Destroyed to point to current thread, then calls sleep to effectively terminate the thread. Scheduler will start running another thread, this thread will examine threadToBeDestroyed and finish it off. 2/17/2019 B.Ramamurthy

Mechanics of Thread Switching Switching the CPU from one thread to another involves suspending the current thread, switching its state (eg: registers), then restoring the state of the thread being switched to. Thread switch is complete the moment the program counter is loaded into the PC. 2/17/2019 B.Ramamurthy

SWITCH routine Routine switch( oldThread, newThread) actually performs a thread switch. Routine switch is written in assembly language and therefore is machine dependent. Semantics of switch: Save all registers in oldThread’s context block. Save the return address in the context block. Load new values into the register from the context block of next thread. Replace PC with the saved PC in the process table; now switch is done. Context switch has taken place. 2/17/2019 B.Ramamurthy

Threads and Scheduling Threads that are ready to run are kept in a ready to run queue. Scheduler is invoked when ever time slice is over or if the current thread wants to give up the CPU. Threads suspended move to the end of the ready list. 2/17/2019 B.Ramamurthy

Scheduler Routines Void ReadyToRun(Thread *thread) Make the thread ready to run and place it in the ready to run list ReadyToRun is invoked for example by the Fork routine. Thread FineNextToRun() Select a ready thread and return it. 2/17/2019 B.Ramamurthy

Run() scheduler method void Run(Thread *nextThread) Suspend the current thread and switch to the new one. Semantics: Check if the current thread overflowed its stack. If yes, reset it. Change the state of new thread to RUNNING. Invoke switch to switch to the next thread. If the previous thread is to be destroyed then do it. (Threads cannot terminate themselves.) We will discuss thread synchronization later. 2/17/2019 B.Ramamurthy