Operating Systems Chapter 5 Threads. Benefits Responsiveness Resource Sharing Economy Utilization of MP Architectures.

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.
Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 6: Threads Chapter 4.
Chapter 5 Threads os5.
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. 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.
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  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
CS238 Lecture 5 Threads Dr. Alan R. Davis. Threads Definitions Benefits User and Kernel Threads Multithreading Models Solaris 2 Threads Java Threads.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Objectives To introduce a notion of a thread.
Process Concept An operating system executes a variety of programs
02/02/2004CSCI 315 Operating Systems Design1 Threads Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
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 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 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 Adapted to COP4610 by Robert van Engelen.
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.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 4: Multithreaded Programming Overview.
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.
Chapter 4: Threads. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Threads A thread (or lightweight process) is a basic unit of CPU.
CHAPTER 5: THREADS ( 线程 ) Overview Overview Multithreading Models (多线程模型) Multithreading Models (多线程模型) Thread Implementation Issues (线程实现事项) Thread Implementation.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Multithreading Models Threading Issues Pthreads Solaris 2 Threads.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
Threads G.Anuradha (Reference : William Stallings)
Source: Operating System Concepts by Silberschatz, Galvin and Gagne.
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 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.
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.
Shan Gao Fall 2007 Department of Computer Science Georgia State University.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
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.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: 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
Threads A thread is an alternative model of program execution
Threads. Thread A basic unit of CPU utilization. An Abstract data type representing an independent flow of control within a process A traditional (or.
Operating System Concepts
Chapter 4: Threads 羅習五. Chapter 4: Threads Motivation and Overview Multithreading Models Threading Issues Examples – Pthreads – Windows XP Threads – Linux.
CISC2200 Threads Fall 09. Process  We learn the concept of process  A program in execution  A process owns some resources  A process executes a program.
Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads  Overview  Multithreading Models  Threading Issues  Pthreads.
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.
A thread is a basic unit of CPU utilization within a process Each thread has its own – thread ID – program counter – register set – stack It shares the.
Threads Some of these slides were originally made by Dr. Roger deBry. They include text, figures, and information from this class’s textbook, Operating.
OPERATING SYSTEM CONCEPT AND PRACTISE
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 4: Threads.
Chapter 5: Threads Overview Multithreading Models Threading Issues
Chapter 5: Threads Overview Multithreading Models Threading Issues
Threads & multithreading
Chapter 5: Threads Overview Multithreading Models Threading Issues
Operating Systems Lecture 13.
Chapter 5: Threads Overview Multithreading Models Threading Issues
Presentation transcript:

Operating Systems Chapter 5 Threads

Benefits Responsiveness Resource Sharing Economy Utilization of MP Architectures

Benefits of Threads / Performance implications Less time to create a thread than a process Less time to terminate thread than a process Less time to switch between two threads within the same process Threads share memory and files; they can communicate without invoking the kernel Higher speed (might reach a factor of 10)

Single and Multithreaded Processes

User Threads Thread Management Done by User-Level Threads Library Examples - POSIX Pthreads - Mach C-threads - Solaris threads - Windows NT - Fibers

ULTs – Advantages and disadvantages Advantages: Thread switching does not require kernel mode privileges; faster Scheduling is application specific; flexible ULTs can run on any O.S. Disadvantages: System calls done by one thread cause the whole process to be blocked Cannot take advantage of multi-processors. Kernel assigns each process to one processor

Kernel Threads Supported by the Kernel Examples - Windows 95/98/NT - Solaris - Digital UNIX

KLTs – Advantages and disadvantages Advantages: Threads do not block each others. Kernel schedules threads independently Kernel can schedule different threads on different processors Kernel routines can be multi-threaded Disadvantage: Transfer of control within one process requires a kernel mode switch

Many-to-One 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 - OS/2

Many-to-many Model

Solaris Process

Threads implementations in Linux Linux uses the same internal representation for processes and threads; a thread is simply a new process that happens to share the same address space as its parent. A distinction is only made when a new thread is created by the clone system call. fork creates a new process with its own entirely new process context clone creates a new process with its own identity, but that is allowed to share the data structures of its parent Using clone gives an application exactly what is shared between two threads.

Threads with WindowsNT Win32API CreateProcess CreateThread CreateFiber ExitProcess ExitThread ExitFiber WaitForSingleObject

POSIX Threads API Don’t forget to compile and link with -lpthread pthread_create – create a new thraed, just like fork create a new process #include int pthread_create( pthread_t *thread, pthread_attr *attr, void *(*start_routine)(void *), void *arg)

More PThread Functions #include void pthread_exit(void *retval); Terminates a thread like exit does to Process #include int pthread_join(pthread_t th,void **thread_return); Just like wait is used to collect child process

Threads in MicroThread /* pointer type to a thread function */ typedef int (far *PThreadFunc) (void *pArg); /* Adds a new thread to the READY queue */ int MTAddNewThread(PThreadFunc pThreadFunc,unsigned priority, unsigned sizeArg, void *pArg); /* Kill a thread */ void MTKillThread(unsigned threadID); /* Kills the current thread */ void MTEndThread(void); /* Kills all known threads dead*/ void MTEndMultiThreading(void); enum MTReturnCode { NORMAL, DEADLOCKED, CTRLBREAK, NOT_INITIALISED,TOO_DEEP_CRITICAL_NEST }; enum /* Starts multi-threading */ MTReturnCode MTStartMultiThreading(void);

MT – Thread Context /* Thread execution context */ typedef struct { unsigned sp; /* stack pointer */ unsigned ss; /* stack segment */ unsigned priority; /* priority: 1,2,3,4 or 5 */ enum ThreadStatus status; unsigned semaphore; /* blocking semaphore */ void *pOwnStack; PThreadFunc pFunc; /* pointer to the thread function */ void *pArg; /* pointer argument passed to the thread function */ void *pMsg; unsigned msgSize; unsigned long wakeUpTime; /* time to wake the sleeping thread up */ unsigned prevID; /* ID of previous thread in the linked-list queue */ unsigned nextID; /* ID of next thread in the linked-list queue */ } ThreadContext; /* The Thread List - implemented as an array of thread execution contexts so that the thread IDs correspond to the array indices */ ThreadContext threads[MAX_THREADS];