Cooperating Processes The concurrent processes executing in the operating system may be either independent processes or cooperating processes. A process.

Slides:



Advertisements
Similar presentations
Threads, SMP, and Microkernels
Advertisements

Chap 4 Multithreaded Programming. Thread A thread is a basic unit of CPU utilization It comprises a thread ID, a program counter, a register set and a.
Threads. Objectives To introduce the notion of a thread — a fundamental unit of CPU utilization that forms the basis of multithreaded computer systems.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
1 Chapter 5 Threads 2 Contents  Overview  Benefits  User and Kernel Threads  Multithreading Models  Solaris 2 Threads  Java Threads.
CHAPTER 5 THREADS & MULTITHREADING 1. Single and Multithreaded Processes 2.
Chapter 4: Multithreaded Programming
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: Multithreaded Programming
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Based on Silberschatz, Galvin and Gagne  2009 Threads Definition and motivation Multithreading Models Threading Issues Examples.
3.5 Interprocess Communication
Threads CSCI 444/544 Operating Systems Fall 2008.
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. 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 Threads Implementation.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: 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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Multithreaded Programming.
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.
14.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 4: Threads.
9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides.
Operating System Principles Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Chapter 4 MultiThreaded Programming. 2015/9/18os Outline Overview Multithreading Models Threading Issues Pthreads Solaris 2 Threads Windows XP/2000.
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.
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.
Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Operating System Concepts Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 13 Threads Read Ch 5.1.
Share Memory Program Example int array_size=1000 int global_array[array_size] main(argc, argv) { int nprocs=4; m_set_procs(nprocs); /* prepare to launch.
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.
PREPARED BY : MAZHAR JAVED AWAN BSCS-III Process Communication & Threads 4 December 2015.
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.
Multithreaded Programing. Outline Overview of threads Threads Multithreaded Models  Many-to-One  One-to-One  Many-to-Many Thread Libraries  Pthread.
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
Lecture 4: Processes & Threads. Lecture 4 / Page 2AE4B33OSS Silberschatz, Galvin and Gagne ©2005 Contents The concept of Process Process states and life-cycle.
Operating System Concepts
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
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.
Contents 1.Overview 2.Multithreading Model 3.Thread Libraries 4.Threading Issues 5.Operating-system Example 2 OS Lab Sun Suk Kim.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
1 Chapter 5: Threads Overview Multithreading Models & Issues Read Chapter 5 pages
Lecture 5. Example for periority The average waiting time : = 41/5= 8.2.
Introduction to threads
OPERATING SYSTEM CONCEPT AND PRACTISE
Threads & multithreading
Operating System Concepts
Operating Systems Processes and Threads.
Chapter 4: Threads.
Threads Chapter 4.
Multithreaded Programming
Chapter 4: Threads.
Presentation transcript:

Cooperating Processes The concurrent processes executing in the operating system may be either independent processes or cooperating processes. A process is independent if it cannot affect or be affected by the other processes executing in the system. Clearly, any process that does not share any data (temporary or persistent) with any other process is independent. On the other hand, a process is cooperating if it can affect or be affected by the other processes executing in the system. Clearly, any process that shares data with other processes is a cooperating process. cooperating processes can communicate in a shared-memory environment. The scheme requires that these processes share a common buffer pool, and that the code for implementing the buffer be written explicitly by the application programmer. Cooperating process is required for following reasons: – Information sharing, computational speedup – Modularity, Convenience Concurrent execution of cooperating processes requires mechanisms that allow processes to communicate with one another and to synchronize their actions. Another way is interprocess communication.

Example

Interprocess Communication IPC provides a mechanism to allow cooperating processes to communicate and to synchronize their actions without sharing the same address space. IPC is particularly useful in a distributed environment where the communicating processes may reside on different computers connected with a network. An example is a chat program used on the World Wide Web. IPC is best provided by a message-passing system, and message systems.

Message-Passing System The function of a message system is to allow processes to communicate with one another without the need to resort to shared data. Communication among the user processes is accomplished through the passing of messages. An IPC facility provides at least the two operations: send(message) and receive(message). Send(destination_name, message) Receiver(source_name, message) Messages sent by a process can be of either fixed or variable size. There are several methods for logically implementing a link and the send/receive operations: – Direct or indirect communication – Symmetric or asymmetric communication – Automatic or explicit buffering – Send by copy or send by reference – Fixed-sized or variable-sized messages

Direct and indirect Direct Communication send (P, message) -send a message to process P. receive (Q, message) -Receive a message from process Q. Indirect Communication send (A, message) -Send a message to mailbox A. receive (A, message) -Receive a message from mailbox A. Mailbox is shared data structure consisting of queues that can temporarily hold messages.

Synchronous and Asynchronous The communication of a message between two processes implies some level of synchronization between the two processes. Message passing may be either blocking or nonblocking- also known as synchronous and asynchronous. Blocking send: The sender is blocked until the requested message is delivered. Nonblocking send: The sending process sends the message and resumes operation. Blocking receive: The receiver blocks until the requested message is delivered/arrived. Nonblocking receive: The receiver retrieves either a valid message or a null.

Three combination are possible using blocking and nonblocking. – Blocking send, blocking receive (Tight synchronization between process) – Nonblocking send, blocking receive (server process that exists to provide a service or resource to other processes) – Nonblocking send, nonblocking receive Nonblocking send consumes more system resources such as buffer space, processor time etc. Blocking receiver is suitable for concurrent tasks.

Buffering Zero capacity (queue with 0 length) Bounded capacity (finite length queue) Unbounded capacity (infinite length queue)

Threads Thread sometimes called a lightweight process. Basic unit of CPU utilization. It comprises a thread ID, a program counter, a register set and stack. Code section, data section, open files and OS resources {address space} shares with other threads belong to same process. A flow of control or execution through the process’s code, with its own thread ID, PC, system registers and stack. Each address space can have multiple concurrent control flows and it is accessed by other threads. Reducing overheads of process switching. May need synchronization to control access to shared variables A traditional (or heavyweight) process has a single thread of control. If the process has multiple threads of control, it can do more than one task at a time.

Thread block Address Space Program counter Registers Stack Thread 1 Single process contains one thread a process with multithreads Address Space Program counterP C RegistersR StackS Thread 1Thread 2

Single and Multithreaded Processes THREADS

Examples: – Web browser use one thread for display image or data and other threads retrieves data from the network. – Word processing (thread for display graphics, reading keystrokes, spelling and grammar checking in background and etc) – Web server (accept client request): Accessing several concurrent client (multithread).

Each process has an address space – Contains code section, data section (global and local variables), open files.. Multithreading - The ability of an OS to support multiple, concurrent paths of execution within a single process Multithreading is the ability of a program or an operating system process to manage its use by more than one user at a time and to even manage multiple requests by the same user without having to have multiple copies of the programming running in the computer. Java supports multithreaded programming, which allows you to write programs that do many things simultaneously Benefits – Responsiveness – Resource sharing – Economy – Utilization of multiprocessor architecture

Benefits of Threads Takes less time to create a new thread than a process Less time to terminate a thread than a process Switching between two threads takes less time than switching between processes Threads enhance efficiency in communication between programs

Type of thread User Level threads: – In user threads, All the work of thread management is done by the application and it is implemented by a thread library at the user level. – The most obvious advantage of user-level threads, it can be implemented on an Operating System that does not support threads. – The thread library contains code for creating and destroying threads, for passing message and data between threads, for scheduling thread execution and for saving and restoring thread context.(no support from the kernel) – Because the kernel is unaware of user-level threads, all thread creation and scheduling are done in user space without the need for kernel intervention. Therefore, user-level threads are generally fast to create and manage. – ULT do not require any hardware support.

drawbacks if the kernel is single- threaded, then any user- level thread performing a blocking system call will cause the entire process to block, even if other threads are available to run within the application. User-thread libraries include POSIX Pthreads, Mach C-threads, and Solaris 2 UI-threads

Kernel level threads In kernel level thread, kernel performs thread creation, scheduling and management in kernel space. because thread management is done by the operating system. There is no thread management code in application area. Kernel threads are supported directly by the operating system. kernel threads are generally slower to create and manage than are user threads. (context switching time is longer in KLT) If on thread in a process is blocked, the kernel can schedule another thread of the same process. Most operating systems-including Windows NT, Windows 2000, Solaris 2, BeOS, and Tru64 UNIX (formerly Digital UN1X)-support kernel threads.

There are two distinct models of thread controls, and they are user-level threads and kernel-level threads. The thread function library to implement user- level threads usually runs on top of the system in user mode. Thus, these threads within a process are invisible to the operating system. User-level threads have extremely low overhead, and can achieve high performance in computation. However, using the blocking system calls like read(), the entire process would block. Also, the scheduling control by the thread runtime system may cause some threads to gain exclusive access to the CPU and prevent other threads from obtaining the CPU. Finally, access to multiple processors is not guaranteed since the operating system is not aware of existence of these types of threads. On the other hand, kernel-level threads will guarantee multiple processor access but the computing performance is lower than user-level threads due to load on the system. The synchronization and sharing resources among threads are still less expensive than multiple-process model, but more expensive than user-level threads. The thread function library available today is often implemented as a hybrid model, as having advantages from both user-level and kernel-level threads. The design consideration of thread packages today consists of how to minimize the system overhead while providing access to the multiple processors

Multithreading Models Some operating system provide a combined user level thread and kernel level thread facility. In combined system, multiple threads within the same application can run in parallel on multiple processors and a blocking system call need not block the entire process. Multithreading models – Many to many relationship – Many to one relationship – One to one relationship

Many-to-One Relationship – In the many-to-one model, many user- level threads are all mapped onto a single kernel thread. – Thread management is done in user space, so it is efficient, but the entire process will block if a thread makes a blocking system call. – Any if user thread invoke blocking system call then entire kernal thread will be blocked. – only one thread can access the kernel at a time, multiple threads are unable to run in parallel on multiprocessors. – Example “divide by zero” give infinite loop at user level which is blocked the kernal thread.

One-to-One Relationship – The one-to-one model creates a separate kernel thread to handle each and every user thread. – Linux and Windows from 95 to XP implement the one-to-one model for threads – It provides more concurrency than the many-to- one model by allowing another thread to run when a thread makes a blocking system call; – it also allows multiple threads to run in parallel on multiprocessors. – The only drawback to this model is that creating a user thread requires creating the corresponding kernel thread. Because the overhead of creating kernel threads can burden the performance of an application, most implementations of this model restrict the number of threads supported by the system.

Many-to-Many Relationship – The many-to-many model multiplexes many user-level threads to a smaller or equal number of kernel threads. – The number of kernel threads may be specific to either a particular application or a particular machine. – In this model, developers can create as many user threads as necessary and the corresponding Kernel threads can run in parallels on a multiprocessor. – If one kernal level thread blocked by one user level thread then other kernal level thread working properly but if one user level thread blocked then related user level thread can be blocked.

Advantages of thread – Use of threads provides concurrency within a process. – Efficient communication. – Economy- It is more economical to create and context switch threads. – Utilization of multiprocessor architectures to a greater scale and efficiency. – Responsiveness – Resource sharing, hence allowing better utilization of resources. – Scalability. One thread runs on one CPU. In Multithreaded processes, threads can be distributed over a series of processors to scale. – Context Switching is smooth. Context switching refers to the procedure followed by CPU to change from one task to another. Thread minimize context switching time.

Multithreading issues The fork( ) and exec( ) System Calls Signal Handling Thread Cancellation Thread-Local Storage Scheduler Activations Privileged instruction done with the help of kernal (OS) [ex: assess system clock] Non provileged instruction done without using kernal.