Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess.

Similar presentations


Presentation on theme: "Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess."— Presentation transcript:

1 Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

2 Thread: - Is basic unit of CPU utilization - A process may ; 1-single thread (light weight ): perform one task at time 2-multithreaded (heavyweight): perform more one task at time - Each thread has: - 1-thread ID - 2- a program counter - Register set - 4- stack Threads of same process share code section,data section,open files

3 In a single threaded application, one thread of execution must do everything If an application has several tasks to perform, those tasks will be performed when the thread can get to them. A single task which requires a lot of processing can make the entire application appear to be "sluggish" or unresponsive. In a multithreaded application, each task can be performed by a separate thread If one thread is executing a long process, it does not make the entire application wait for it to finish. If a multithreaded application is being executed on a system that has multiple processors, the OS may execute separate threads simultaneously on separate processors. Why use Multithreading?

4 Any kind of application which has distinct tasks which can be performed independently Any application with a GUI. Threads dedicated to the GUI can delegate the processing of user requests to other threads. The GUI remains responsive to the user even when the user's requests are being processed Any application which requires asynchronous response What Kind of Applications Use Multithreading?

5 Multithreaded Server Architecture

6 Single and Multithreaded Processes

7 Benefits Responsiveness Resource Sharing Economy Scalability

8 Multi Threading Models

9 Multithreading models There are three dominant models for thread libraries, each with its own trade-offs  many threads on one LWP (many-to-one)  one thread per LWP (one-to-one)  many threads on many LWPs (many-to-many) Similar models can apply on scheduling kernel threads to real CPUs

10 Many-to-One Many user-level threads mapped to single kernel thread

11 Many-to-one In this model, the library maps all threads to a single lightweight process Advantages:  totally portable  easy to do with few systems dependencies Disadvantages:  cannot take advantage of parallelism  may have to block for synchronous I/O  there is a clever technique for avoiding it Mainly used in language systems, portable libraries

12 One-to-One Each user-level thread maps to kernel thread Examples  Windows NT/XP/2000  Linux  Solaris 9 and later

13 One-to-one In this model, the library maps each thread to a different lightweight process Advantages:  can exploit parallelism, blocking system calls Disadvantages:  thread creation involves LWP creation  each thread takes up kernel resources  limiting the number of total threads Used in LinuxThreads and other systems where LWP creation is not too expensive

14 Many-to-Many Model Allows many user level threads to be mapped to many kernel threads Allows the operating system to create a sufficient number of kernel threads Solaris prior to version 9 Windows NT/2000 with the ThreadFiber package

15 Many-to-many In this model, the library has two kinds of threads: bound and unbound  bound threads are mapped each to a single lightweight process  unbound threads may be mapped to the same LWP Probably the best of both worlds Used in the Solaris implementation of Pthreads (and several other Unix implementations)

16 Threading Issues Semantics of fork() and exec() system calls Thread cancellation of target thread  Asynchronous or deferred Thread pools Thread-specific data

17 Semantics of fork() and exec() Does fork() duplicate only the calling thread or all threads?

18 Thread Cancellation Terminating a thread before it has finished Two general approaches:  Asynchronous cancellation terminates the target thread immediately  Deferred cancellation allows the target thread to periodically check if it should be cancelled

19 Signal Handling Signals are used in UNIX systems to notify a process that a particular event has occurred A signal handler is used to process signals 1. Signal is generated by particular event 2. Signal is delivered to a process 3. Signal is handled Options:  Deliver the signal to the thread to which the signal applies  Deliver the signal to every thread in the process  Deliver the signal to certain threads in the process  Assign a specific threa to receive all signals for the process

20 Thread Pools Create a number of threads in a pool where they await work Advantages:  Usually slightly faster to service a request with an existing thread than create a new thread  Allows the number of threads in the application(s) to be bound to the size of the pool

21 Thread Specific Data Allows each thread to have its own copy of data Useful when you do not have control over the thread creation process (i.e., when using a thread pool)

22 Windows XP Threads Implements the one-to-one mapping, kernel-level Each thread contains  A thread id  Register set  Separate user and kernel stacks  Private data storage area The register set, stacks, and private storage area are known as the context of the threads The primary data structures of a thread include:  ETHREAD (executive thread block)  KTHREAD (kernel thread block)  TEB (thread environment block)

23 Linux Threads Linux refers to them as tasks rather than threads Thread creation is done through clone() system call clone() allows a child task to share the address space of the parent task (process)

24 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, End of Chapter 4

25

26 Thread:


Download ppt "Lecturer 3: Processes multithreaded Operating System Concepts Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess."

Similar presentations


Ads by Google