Threads-Process Interaction. CONTENTS  Threads  Process interaction.

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

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.
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,
Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads.
Chapter 5 Processes and Threads Copyright © 2008.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
3.5 Interprocess Communication
Threads CSCI 444/544 Operating Systems Fall 2008.
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.
Process Concept An operating system executes a variety of programs
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.
Process Description and Control. Process concepts n Definitions – replaces task, job – program in execution – entity that can be assigned to and executed.
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.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
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.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
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)
CS333 Intro to Operating Systems Jonathan Walpole.
Processes and Process Control 1. Processes and Process Control 2. Definitions of a Process 3. Systems state vs. Process State 4. A 2 State Process Model.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
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.
Operating System 4 THREADS, SMP AND MICROKERNELS.
Department of Computer Science and Software Engineering
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 A basic unit of CPU utilization. An Abstract data type representing an independent flow of control within a process A traditional (or.
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.
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-
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
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,
Processes and threads.
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 4 Threads.
Principles of Operating Systems Lecture 8
Operating Systems Processes and Threads.
Chapter 3 Process Management.
Threads, SMP, and Microkernels
Lecture 4- Threads, SMP, and Microkernels
Operating System 4 THREADS, SMP AND MICROKERNELS
Threads and Concurrency
Threads Chapter 4.
Presentation transcript:

Threads-Process Interaction

CONTENTS  Threads  Process interaction

THREADS

Address space of a process  Process image (program, data, stack, PCB)  Allocated resources: (open files, main memory, I/O devices,…)

 Process properties: distinguished address spaces (Unix)  The operations on processes and context switch are rather time consuming (overhead)

The concept of a process embodies two requirements: Resource ownership Resources can be allocated to processes, e.g., memory, I/O devices…

Scheduling/execution A process has an execution state, a priority, and processes are the entities scheduled by the O.S.

the unit of dispatching is usually referred to as a thread or lighthweight process

the unit of resource ownership is usually still referred to as a process or a task

Multithreading: the ability of an O.S. to support multiple threads within a single process

All the threads of a process share in the same process address space and have access to the same data

 A thread execution state (running, ready,..)  A saved thread context, when not in execution Any thread has several associated entities:

One process one thread One process multiple threads Multiple processes one thread per process Multiple processes multiple threads per process

THREADS BENEFITS: It takes less time  to create and terminate a thread than a process  to switch between two threads within the same process

Threads enhance efficiency in communication, because threads within the same process share memory and files

THREAD IMPLEMENTATION Thread management is in charge of the application and the kernel is not aware of thread existence User-level threads

A thread library is typically used, wich is a package of routines for thread management THREAD IMPLEMENTATION User-level threads

 creating and destroying threads  passing messages and data betweeen threads The thread library contains code for:

 scheduling thread execution and saving and restoring thread context The thread library contains code for:

When a thread executes a system call, all the threads within that process are blocked Disavantages of user-level threads

A multithreaded application cannot take advantage of multiprocessing Disavantages of user-level threads

Kernel-level threads (NT, Linux)  The whole thread management is made by the O.S.

 There is no thread management code in the application area, but only a simple API to address to the kernel thread facility Kernel-level threads (NT, Linux)

The main disavantage of the this approach is that the switch between two threads within the same process requires a mode switch to the kernel

A multithreaded application can take advantage of multiprocessing

PROCESS INTERACTION

CONCURRENT PROCESSES Set of processes which execute simultaneously

Two processes are concurrent if the first operation of one of them begins before the last operation of the other CONCURRENT PROCESSES

P1P1 P1P1 P2P2 P2P2 P1P1 P1P1 P2P2 P2P2 P1P1 P1P1 P2P2 P2P2 P1P1 P1P1 P2P2 P2P2 t t overlapping interleaving t t CONCURRENT PROCESSES

Independent processes: a set of processes is indipendent if each process of the set cannot affect or be affected by the others processes CONCURRENT PROCESSES

Cooperating processes: a set of processes is cooperating if each of them can affect or be affected by any other process

 The result of the cooperation depends from race conditions of the processes  The behaviour of a set of cooperating processes is not reproducible

PROCESS INTERACTION Competition:behavior exibited in the use of common resources that cannot be used simultaneously (because of mutual exclusion)

Cooperation: execution of a common activity obtained by the exchange of information (via communication) PROCESS INTERACTION

MUTUAL EXCLUSION process A The file can be inserted in the position 7 file A file B file C file D full empty A and B intend to insert a file in the table process B

MUTUAL EXCLUSION process A file A file B file C file D empty process B 1 Following the reading of the value 7 by A, A is suspended

MUTUAL EXCLUSION process A file A file B file C file D empty process B 2 B reads the value 7, inserts the file E and increases the value of the variable empty to 8 8 file E

MUTUAL EXCLUSION process A file A file B file C file D empty process B 8 file xxx 3A resumes its execution and inserts the file xxx in 7 (the previous value is deleted)

COMMUNICATION buffer P1 P2 produce message enter message consume message remove message

 Correct sequence of operations: enter - remove – enter - remove- …  Incorrect sequence of operations: remove – remove – enter - … COMMUNICATION

In the previous examples, in order to obtain a correct system behaviour,... SYNCHRONIZATION

... it is necessary to impose timing constraints to the execution of the process operations SYNCHRONIZATION

Competition: only one process at a time must access to a common resource (indirect or implicit synchronization) SYNCHRONIZATION constraints

Cooperation: the order of operations observed by producers and consumers on the buffer must follow a fixed policy,... SYNCHRONIZATION constraints

... such as an alternation schedule (direct or explicit synchronization) SYNCHRONIZATION constraints

PROCESS INTERACTION MODELS  global environment model  message passing model

The process system may be considered as a set of processes and resources (objects) GLOBAL ENVIRONMENT MODEL

O3 O1 O2 O4 P1 P2 P3 O2, O3 common res. competition cooperation O1, O4 private res. GLOBAL ENVIRONMENT MODEL

The process system may be considered as a set of processes,... Messagge passing model

... each of them working in a local environment, i.e., not directly accessibile by other processes Messagge passing model

P1P2 Pn channel Messagge passing model

Any type of interactions among processes (communication, synchronization) requires a message exchange

Resources are typically not directly accessibles to processes Any resource is associated to a specific server process

BUFFERPP producer CC consumer

 The producer cannot enter a message in the buffer, if the buffer is full  The consumer cannot remove a message from the buffer, if the buffer is empty

d = num. of entered messages e = num. of removed messages N = size of the buffer O  d-e  N