Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 10: Threads Implementation

Similar presentations


Presentation on theme: "Lecture 10: Threads Implementation"— Presentation transcript:

1 Lecture 10: Threads Implementation

2 Review: POSIX Standards
pthread_create() pthread_exit() pthread_join() pthread_yield()

3 In this lecture Threads implementation User Level Threads
Kernel Level Threads Hybrid Implementations

4 What is a Thread? Execution context
Registers, Stack Shared text, heap, static data segments Thread execution context smaller than process execution context

5 User Space Threads All the thread support provided by a user level library Kernel not even aware that the program has multiple threads User library also handles synchronization (mutexes, condition variables, etc)

6 Implementing Threads in User Space
A user-level threads package

7 Pros of User Space Implementation
Can be used in OSes which don’t implement threads Thread related operations are fast (no system calls) creation Each process can have its own thread scheduling algorithm Thread scheduling is also faster

8 Cons of User Space Implementation
System calls/page faults block and other threads will not be able to execute No benefits of multi-threading Possible solutions Change system calls to be nonblocking Wrap system calls. Check whether it is safe before making system calls

9 Implementing Threads in the Kernel
A threads package managed by the kernel

10 Kernel Space Pros: Cons: Can take advantage of multiple processors
System call/page fault blocks only the thread which made the call Cons: Thread operations involve system calls (expensive) Solution: recycle threads

11 Hybrid Implementations
Multiplexing user-level threads onto kernel- level threads

12 Processes & Threads Resource ownership – Process or Task
Scheduling/execution – Thread or lightweight process One process, one thread (MS-DOS) One process, multiple threads (Java Runtime) Multiple processes, one thread per process (Unix) Multiple processes, multiple threads (W2K, Solaris, Linux)

13 Single Threaded and Multithreaded Process Models

14 Key Benefits of Threads

15 User and Kernel-Level Threads Performance
Null fork: the time to create, schedule, execute, and complete a process/thread that invokes the null procedure. Signal-Wait: the time for a process/thread to signal a waiting process/thread and then wait on a condition. Procedure call: 7us Kernel Trap:17us Thread Operation Latencies Operation ULT KLT Process Null fork ,300 Signal Wait ,840 Observation While there is a significant speedup by using KLT multithreading compared to single-threaded processes, there is an additional significant speedup by using ULTs. However, whether or not the additional speedup is realized depends on the nature of the applications involved. If most of the thread switches require kernel mode access, then ULT may not perform much better than KLT.


Download ppt "Lecture 10: Threads Implementation"

Similar presentations


Ads by Google