Inter-Process Communication  most OSs provide several abstractions for inter- process communication: message passing, shared memory, etc.  communication.

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

Chapter 4 Threads Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
Threads, SMP, and Microkernels
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
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.
1 Threads, SMP, and Microkernels Chapter 4. 2 Process: Some Info. Motivation for threads! Two fundamental aspects of a “process”: Resource ownership Scheduling.
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. 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.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
© 2004, D. J. Foreman 2-1 Concurrency, Processes and 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.
Operating Systems Lecture 09: Threads (Chapter 4)
Chapter 4: Threads. From Processes to Threads 4.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th edition, Jan 23, 2005 Threads.
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.
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)
CS333 Intro to Operating Systems Jonathan Walpole.
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.
1 Lecture 4: Threads Advanced Operating System Fall 2010.
Chapter 4: Threads. 2 Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads.
ITFN 3601 Introduction to Operating Systems Lecture 3 Processes, Threads & Scheduling Intro.
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.
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.
Threads, Thread management & Resource Management.
Threads-Process Interaction. CONTENTS  Threads  Process interaction.
Threads. Readings r Silberschatz et al : Chapter 4.
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
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 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.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
CS 6560: Operating Systems Design
Chapter 4 Threads.
Threads & multithreading
Threads, SMP, and Microkernels
Threads Chapter 4.
Lecture 4- Threads, SMP, and Microkernels
Threads and Concurrency
Threads Chapter 4.
CS Introduction to Operating Systems
Presentation transcript:

Inter-Process Communication  most OSs provide several abstractions for inter- process communication: message passing, shared memory, etc.  communication requires synchronization between processes (i.e. data must be produced before it is consumed)  synchronization can be implicit (message passing) or must be explicit (shared memory)  explicit synchronization can be provided by the OS (semaphores, monitors, etc..) or can be achieved exclusively in user-mode (later in the course)

Message Passing Implementation  two copy operations in a conventional implementation x=1 send(process2, &X) receive(process1,&Y) print Y process 1 process 2 X Y kernel buffers 1st copy 2nd copy kernel

Shared Memory Implementation  no copying but synchronization is necessary X=1 print Y process 1 process 2 X Y kernel physical memory shared region

Lecture 5: Threads

Threads  the process concept incorporates two abstractions:  a virtual processor (an execution context)  a resource ownership (an address space, open files etc..)  within an address space, we can have more units of execution: threads  all the threads of a process share the same address space and the same resources

Multithreaded Environment  Process  all resources allocated: IPC channels, files etc..  a virtual address space that holds the process image  Threads  an execution state: running, ready, etc..  an execution context: PC, SP, other registers  a per-thread stack

Threads vs. Processes  operations on threads (creation, termination, scheduling, etc..) are cheaper than the corresponding operations on processes  inter-thread communication is supported through shared memory without kernel intervention  Advantages  Disadvantages  easy to introduce race conditions  synchronization is necessary

Posix Thread (Pthread) API _ thread creation and termination pthread_create(&tid,NULL,start_fn,arg); pthread_exit(status)’ _ thread join pthread_join(tid, &status); _ mutual exclusion pthread_mutex_lock(&lock); pthread_mutex_unlock(&lock); _ condition variable pthread_cond_wait(&c,&lock); pthread_cond_signal(&c);

Condition Variables (example) _ thread 1 pthread_mutex_lock(&lock); while (!my-condition); pthread_cond_wait(&c,&lock); do_critical_section(); pthread_mutex_unlock(&lock); _ thread 2 pthread_mutex_lock(&lock); my-condition = true; pthread_mutex_unlock(&lock); pthread_cond_signal(&c);

Process  Have a virtual address space, which holds the process image  Protected access to processors, other processes, files, and I/O resources

Thread  An execution state (running, ready, etc.)  Saved thread context (when not running)  Has an execution stack  Per-thread static storage for local variables  Access to the memory and resources of the process it belongs to  all threads of the same process share this

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

Kernel-Level Threads  Kernel maintains context information for the process and the threads  Scheduling is done on a thread basis

Thread Implementation  user-level threads  implemented as a thread library, which contains the code for thread creation, termination, scheduling and switching  kernel sees one process and it is unaware of its thread activity  can be preemptive or not (co-routines)  kernel-level threads (lightweight processes)  thread management done by the kernel

User-Level vs. Kernel-Level Threads  Advantages of the user-level threads  performance: low-cost thread operations (do not require crossing protection domains)  flexibility: scheduling can be application specific  portability: user-level thread library easy to port  Disadvantages of the user-level threads  if a user-level thread is blocked in the kernel, the entire process (all threads of that process) are blocked  cannot take advantage of multiprocessing (the kernel assigns one process to only one processor)

User-Level vs. Kernel-Level Threads (cont’d) process processor user-level threads thread scheduling process scheduling processor kernel-level threads thread scheduling kernel user

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-Level Thread Implementation code process kernel thread 1 pc sp pc sp thread 2 thread stacks data