Presentation on theme: "3.5 Interprocess Communication"— Presentation transcript:
1 3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC)Processes must communicate with one another in multiprogrammed and networked environmentsFor example, a Web browser retrieving data from a distant serverEssential for processes that must coordinate activities to achieve a common goal
2 3.5.1 SignalsSoftware interrupts that notify a process that an event has occurredDo not allow processes to specify data to exchange with other processesProcesses may catch, ignore or mask a signalCatching a signal involves specifying a routine that the OS calls when it delivers the signalIgnoring a signal relies on the operating system’s default action to handle the signalMasking a signal instructs the OS to not deliver signals of that type until the process clears the signal mask
3 3.5.2 Message Passing Message-based interprocess communication Messages can be passed in one direction at a timeOne process is the sender and the other is the receiverMessage passing can be bidirectionalEach process can act as either a sender or a receiverMessages can be blocking or nonblockingBlocking requires the receiver to notify the sender when the message is receivedNonblocking enables the sender to continue with other processingPopular implementation is a pipeA region of memory protected by the OS that serves as a buffer, allowing two or more processes to exchange data
4 3.6 Case Study: UNIX Processes All processes are provided with a set of memory addresses, called a virtual address spaceA process’s PCB is maintained by the kernel in a protected region of memory that user processes cannot accessA UNIX PCB stores:The contents of the processor registersPIDThe program counterThe system stackAll processes are listed in the process table
5 3.6 Case Study: UNIX Processes UNIX processes continuedAll processes interact with the OS via system callsA process can spawn a child process by using the fork system call, which creates a copy of the parent processChild receives a copy of the parent’s resources as wellProcess priorities are integers between -20 and 19 (inclusive)A lower numerical priority value indicates a higher scheduling priorityUNIX provides IPC mechanisms, such as pipes, to allow unrelated processes to transfer data
6 3.6 Case Study: UNIX Processes Figure 3.10 UNIX system calls.
7 Group Discussion 11/31/08, due in class1. What does a process’s address space look like?2. T/F There could be a process not assigned to the processor and not waiting for I/O.3. From where does an OS load the execution context for the process to be dispatched?4. If no interrupts are allowed in a system, what will the system do to handle I/O?5. What state will be assigned to a process when it is timed out?6. T/F Division by zero is an example of asynchronous interrupt generated by processor.7. What is an interrupt handler? What is an interrupt vector?8. Name two types of IPC.9. T/F A blocking send is asynchronous communication.
8 Chapter 4 – Thread Concepts Outline Introduction 4.2 Definition of Thread4.3 Motivation for Threads4.4 Thread States: Life Cycle of a Thread4.5 Thread Operations4.6 Threading Models4.6.1 User-Level Threads4.6.2 Kernel-Level Threads4.6.3 Combining User- and Kernel-Level Threads4.7 Thread Implementation Considerations4.7.1 Thread Signal Delivery4.7.2 Thread Termination4.8 POSIX and Pthreads4.9 Linux Threads4.10 Windows XP Threads4.11 Java Multithreading Case Study, Part 1: Introduction to Java Threads
9 Objectives After reading this chapter, you should understand: the motivation for creating threads.the similarities and differences between processes and threads.the various levels of support for threads.the life cycle of a thread.thread signaling and cancellation.the basics of POSIX, Linux, Windows XP and Java threads.
10 4.1 IntroductionGeneral-purpose languages such as Java, C#, Visual C++ .NET, Visual Basic .NET and Python have made concurrency primitives available to applications programmerMultithreadingProgrammer specifies applications contain threads of executionEach thread designate a portion of a program that may execute concurrently with other threads
11 4.2 Definition of Thread Thread Lightweight process (LWP)Threads of instructions or thread of controlShares address space and other global information with its processRegisters, stack, signal masks and other thread-specific data are local to each threadThreads may be managed by the operating system or by a user applicationExamples: Win32 threads, C-threads, Pthreads
12 Figure 4.1 Thread Relationship to Processes. 4.2 Definition of ThreadFigure 4.1 Thread Relationship to Processes.
13 4.3 Motivation for Threads Threads have become prominent due to trends inSoftware designMore naturally expresses inherently parallel tasksPerformanceScales better to multiprocessor systemsCooperationShared address space incurs less overhead than IPC
14 4.3 Motivation for Threads Each thread transitions among a series of discrete thread statesThreads and processes have many operations in common (e.g. create, exit, resume, and suspend)Thread creation does not require operating system to initialize resources that are shared between parent processes and its threadsReduces overhead of thread creation and termination compared to process creation and termination
15 4.4 Thread States: Life Cycle of a Thread Figure 4.2 Thread life cycle.
16 4.6.1 User-level ThreadsUser-level threads perform threading operations in user spaceThreads are created by runtime libraries that cannot execute privileged instructions or access kernel primitives directlyUser-level thread implementationMany-to-one thread mappingsOperating system maps all threads in a multithreaded process to single execution contextAdvantagesUser-level libraries can schedule its threads to optimize performanceSynchronization performed outside kernel, avoids context switchesMore portableDisadvantageKernel views a multithreaded process as a single thread of controlCan lead to suboptimal performance if a thread issues I/OCannot be scheduled on multiple processors at once
18 4.6.2 Kernel-level ThreadsKernel-level threads attempt to address the limitations of user-level threads by mapping each thread to its own execution contextKernel-level threads provide a one-to-one thread mappingAdvantages: Increased scalability, interactivity, and throughputDisadvantages: Overhead due to context switching and reduced portability due to OS-specific APIsKernel-level threads are not always the optimal solution for multithreaded applications
20 4.6.3 Combining User- and Kernel-level Threads The combination of user- and kernel-level thread implementationMany-to-many thread mapping (m-to-n thread mapping)Number of user and kernel threads need not be equalCan reduce overhead compared to one-to-one thread mappings by implementing thread poolingWorker threadsPersistent kernel threads that occupy the thread poolImproves performance in environments where threads are frequently created and destroyedEach new thread is executed by a worker threadScheduler activationTechnique that enables user-level library to schedule its threadsOccurs when the operating system calls a user-level threading library that determines if any of its threads need rescheduling