Presentation is loading. Please wait.

Presentation is loading. Please wait.

Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating.

Similar presentations


Presentation on theme: "Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating."— Presentation transcript:

1 Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating threads, and preemptively switches control among (kernel- level) threads. A thread is simply a function that can call other functions.

2 Multithreading Threads are part of same process and share all process resources: Memory Open Files Global Variables Static Variables Each thread has its own: processor (and math coprocessor) state stack

3 Single and Multithreaded Processes

4 Lightweight process. Threads share all process resources. State: Thread ID, program counter, register set, and stack. User-level threads and kernel-level threads.

5 Benefits Performance: Overlap communication/computation Responsiveness: Separate thread to handle user input. Web server spawns separate thread to handle incoming request. Resource Sharing: e.g., one code, data segment. Economy: Much cheaper to create and switch than processes. Utilization of MP Architectures: Assign each thread to a separate processor if available.

6 User Threads Thread management done by user-level threads library. Advantages: Very fast: Does not involve kernel in creation, scheduling, or switching. Disadvantages: When a thread blocks, whole process blocks.

7 Kernel Threads Supported by the Kernel. Kernel creates, schedules, and switches threads. Advantage: When one thread blocks, the whole process does not have to block. Thus can overlap I/O and computation. Disadvantage: Slower since kernel is involved.

8 Multithreading Models Many-to-One One-to-One Many-to-Many

9 Many-to-One Many user-level threads mapped to single kernel thread. Used on systems that do not support kernel threads.

10 Many-to-One Model

11 One-to-One Each user-level thread maps to kernel thread. Examples - Windows 95/98/NT/2000 - OS/2

12 One-to-one Model

13 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 2 Windows NT/2000 with the ThreadFiber package

14 Many-to-Many Model

15 Pthreads a POSIX standard (IEEE 1003.1c) API for thread creation and synchronization. API specifies behavior of the thread library, implementation is up to development of the library. Common in UNIX operating systems.

16 Solaris 2 Threads

17 Solaris Process

18 Windows 2000 Threads Implements the one-to-one mapping. Each thread contains - a thread id - register set - separate user and kernel stacks - private data storage area


Download ppt "Multithreading Allows application to split itself into multiple “threads” of execution (“threads of execution”). OS support for creating threads, terminating."

Similar presentations


Ads by Google