Threads, SMP, and Microkernels Chapter 4. Two Characteristics of Processes (1) Resource ownership zA process is allocated a virtual address space to hold.

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
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 5 Threads os5.
Computer Systems/Operating Systems - Class 8
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
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.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.
Operating Systems (OS) Threads, SMP, and Microkernel, Unix Kernel
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
3.5 Interprocess Communication
1 Chapter 4 Threads Threads: Resource ownership and execution.
Threads, SMP, and Microkernels
UNIX Process Creation Every process, except process 0, is created by the fork() system call fork() allocates entry in process table and assigns a unique.
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.
A. Frank - P. Weisberg Operating Systems Threads Implementation.
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.
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.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Threads, SMP, and Microkernels Chapter 4. 2 Outline n Threads n Symmetric Multiprocessing (SMP) n Microkernel n Linux Threads.
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.
Multithreading in Java Project of COCS 513 By Wei Li December, 2000.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for.
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.
Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process.
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.
Operating System 4 THREADS, SMP AND MICROKERNELS.
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.
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
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 Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Chapter 4 – Thread Concepts
Chapter 4 – Thread Concepts
Chapter 4 Threads.
Operating Systems: A Modern Perspective, Chapter 6
Threads, SMP, and Microkernels
Lecture 4- Threads, SMP, and Microkernels
Operating System 4 THREADS, SMP AND MICROKERNELS
Threads Chapter 4.
Chapter 4 Threads, SMP, and Microkernels
CS510 Operating System Foundations
Presentation transcript:

Threads, SMP, and Microkernels Chapter 4

Two Characteristics of Processes (1) Resource ownership zA process is allocated a virtual address space to hold the process image zA process, from time to time, may be assigned main memory plus control of other resources, such as I/O channels, I/O devices, and files.

Two Characteristics of Processes (2) Dispatching zA process is an execution path (trace) through one or more programs. yexecution may be interleaved with other processes (parent process and child process) zA process has an execution state (Running, Ready, Blocked, Blocked Suspend, Read Suspend)

Dispatching and Thread zThese two characteristics are treated independently by the operating system zResource of ownership is referred to as a process or task zDispatching is referred to as a thread

Thread zA thread is a piece of program code executed in a serial fashion. zA thread is a dispatchable of work. It executes sequentially and is interruptable so that the processor can turn to another thread. zA process is a collection of one or more threads and associated system resources.

Multithreading zMultithreading Operating system supports multiple threads of execution within a single process

Threads and Processes one process one thread multiple processes one thread per process one process multiple threads multiple processes multiple threads per process

Single Threaded and Multithreaded Process Models Thread Control Block User Stack User Stack Kernel Stack Kernel Stack User Address Space User Address Space Process Control Block Process Control Block Thread Single-Threaded Process Model Multithreaded Process Model Thread Control Block User Stack Kernel Stack Thread Control Block User Stack Kernel Stack Thread

Relationship Between Threads and Processes Threads:ProcessDescriptionExample Systems 1:1Each thread of execution is a unique process with its own address space and resources. Most UNIX implementations M:1 A process defines an address space and dynamic resource ownership. Multiple threads may be created and executed within that process. Windows NT, Solaris, OS/2, OS/390, MACH

Relationship Between Threads and Processes Threads:ProcessDescriptionExample Systems 1:MA thread may migrate from one process environment to another. This allows a thread to be easily moved among distinct systems. Ra (Clouds), Emerald M:MCombines attributes of M:1 and 1:M cases TRIX

Examples of threading & Multithreading zMS-DOS supports a single process and a single thread. zJava support a single process with multiple threads zUNIX supports multiple user processes but only supports one thread per process zSolaris and Windows NT supports multiple user processes, each of which supports multiple threads

fork System Call 1. Syntax of fork System Call Include File(s): Summary: pid_t fork (void); Return Success : 0 in child, child PID in parent Failure: -1 Set errno: yes 2. Function of fork System Call When a fork system call is made, the operating system generates a copy of the parent process which becomes the child process. Process Dr. Ming Zhang

thr_create API (Application Program Interface) (1) 1. The thr_create Function Prototype Include File: int thr_create(void* stackp, size_t stack_size, void* (*funcp)(void*), void* argp, long flags, thread_t* tid_p); 2. Function of thr_create( ) The function creates a new thread to execute a function whose address is given in the funcp argument. Dr. Ming Zhang

thr_create API (2) 3. Return Success : 1 Failure: 0 4. void* stackp The address of a user-defined memory region. This memory is used as the new thread run- time stack. If the stackp value is NULL, the function allocates a stack region of stack_size bytes. 5 size_t stack_size The size of a user-defined memory region. This memory is used as the new thread run-time stack. If the stack_size value is 0, the function uses a system default value that is one megabyte. Dr. Ming Zhang

thr_create API (3) 6. void* (*funcp) (void*) The function specified in funcp should accept one void*-typed input argument and return void* data. 7. void* argp The actual argument to be passed to the funcp function, when the new thread starts executing, is specified in the argp argument. Dr. Ming Zhang

thr_create API (4) 8. long flags The flags argument value may be zero, meaning that no special attributes are assigned to the new thread. The flags value may using one or more of the following bit-flags: THR_SUSPENDED: suspends the execution of the new thread until another thread calls the thr_continue function to enable it to execute THR_NEW_LWP: Create a new LWP (LightWeight Process) along with the new thread. Dr. Ming Zhang

thr_create API (5) 9. thread_t* tid_p); The new thread ID is return via the tid_p argument. If the actual value of the tid_p argument is assigned NULL, no thread ID is returned. The thread ID data type is thread_t. Dr. Ming Zhang

thr_create API (6 ) # include thread_t tid; //for return thread ID void* send_msg(void* ptr);// function executed by thread MSGREC * pREC ; // MSGRC: struct name int main ( ) { thr_create( 0, 0, send_msg, pRec, THR_SUSPENDD, &tid); } Dr. Ming Zhang

Threads differ from Chile Processes (1) zThreads may be managed by either user- level library functions or the operating system kernel. zChild processes as created by the fork system call are managed by the operating system kernel

Threads differ from Chile Processes (2) zAll threads in a process share the same data and code segment. zA child process has its own copy of virtual address space that is separate from its parent process.

Threads differ from Chile Processes (3) zIf a thread calls the exit or exec function, it terminates all the threads in the same process. zIf a child process calls the exit or exec function, its parent process is not affected.

Threads differ from Chile Processes (4) zIf a thread modifies a global variable in a process, the changes are visible to other threads in the same process. zIf a child process modifies a global variable. the changes are NOT visible to the parent process.

Benefits of Threads (1) zThreads is more efficient, and require much less kernel attention, to create and manage than do child process, because threads are managed by user-level library function and kernel. zThreads use much less system resources than do child process, because thread can share the data in same process.

Benefits of Threads (2) zTakes less time to create a new thread than a process zLess time to terminate a thread than a process zLess time to switch between two threads within the same process zSince threads within the same process share memory and files, they can communicate with each other without invoking the kernel

Thread Structure zA thread ID zA run-time stack zA set of register (e.g., program counter and stack pointer) zA signal mask zA schedule priority zA thread-specific storage

Thread Features (1) zHas an execution state (running, ready, etc.) zSaves thread context when not running zHas an execution stack zHas some per-thread static storage for local variables zHas access to the memory and resources of its process yall threads of a process share this

Thread Features (2) zSuspending a process involves suspending all threads of the process since all threads share the same address space zTermination of a process, terminates all threads within the process

Synchronization of Using Threads zSome synchronization methods are needed for threads accessing shared data, because if a thread modifies a global variable in a process, the changes are visible to other threads in the same process.

Benefits of Using Multithreaded Programming zIt allows a process to make use of any available multiprocessor hardware on any system it is run on. zIt allows programmers to structure their code into independently executable units and maximize concurrency. zThreads reduce the need to use fork to create child processes, thus improving each process performance (less context switching).

User-Level Threads zAll thread management is done by the application zThe kernel is not aware of the existence of threads zThread switching does not require kernel mode privileges zScheduling is application specific

Kernel-Level Threads zThere is no thread management code in the application area, simply an application programming interface (API) to the kernel facility. (Windows NT) zKernel maintains context information for the process and the threads zSwitching between threads requires the kernel

Combined Approaches for Threads zSolaris operating systems provide a combined ULT/KLT facility zThread creation is done completely in the user space, as is the bulk of scheduling and synchronization of threads within an application. zThe multiple ULTs from a single application are mapped onto smaller or equal number KLTs.

Solaris Multithreaded Architecture process 1 process 2 process 3 User L L L L L Kernel Hardware P P P L: Lightweight Process; P: Processor; :ULT; : KLT

Symmetric Multiprocessing zMIMD A set of processors simultaneously execute different instruction sequences on different data sets zShared memory multiprocessor (Distributed Memory MIMD is clusters) zKernel can execute on any processor zTypically each processor does self- scheduling form the pool of available process or threads

Symmetric Multiprocessor Organization Main Memory Processor Cache I/O Subsystem...

Categories of Computer Systems (1) zSingle Instruction Single Data (SISD) ysingle processor executes a single instruction stream to operate on data stored in a single memory zSingle Instruction Multiple Data (SIMD) yone instruction is executed on a different set of data by the different processors

Categories of Computer Systems (2) zMultiple Instruction Single Data (MISD) ya sequence of data is transmitted to a set of processors, each of which executes a different instruction sequence. zMultiple Instruction Multiple Data (MIMD) ya set of processors simultaneously execute different instruction sequences on different data sets

Microkernel zSmall operating system core zContains only essential operating systems functions zMany services traditionally included in the operating system are now external subsystems ydevice drivers yfile systems yvirtual memory manager ywindowing system and security services

Benefits of a Microkernel Organization (1) zUniform interface on request made by a process yall services are provided by means of message passing zExtensibility yallows the addition of new services zFlexibility yexisting features can be subtracted

Benefits of a Microkernel Organization (2) zPortability ychanges needed to port the system to a new processor is changed in the microkernel - not in the other services zReliability ymodular design ysmall microkernel can be rigorously tested

Benefits of Microkernel Organization (3) zDistributed system support ymessage are sent without knowing what the target machine is zObject-oriented operating system ycomponents are objects with clearly defined interfaces that can be interconnected to form software

Solaris zProcess includes the user’s address space, stack, and process control block zUser-level threads zLightweight processes A lightweight process can be viewed as a mapping between ULTs and KLTs. zKernel threads

Solaris User Level Threads Stop Sleep Dispatch Stop Wakeup Continue Preempt Stopped Runnable Active Sleeping

Solaris Lightweight Processes Timeslice or Preempt Wakeup Stop Blocking System Call Wakeup Dispatch Runnable Running Blocked Stopped Continue Stop