Lecture 10: Threads Implementation

Lecture 10: Threads Implementation

Lecture 10: Threads Implementation 1 Review: POSIX Standards pthread_create()

pthread_exit() pthread_join() pthread_yield() 2 In this lecture Threads implementation User Level Threads Kernel Level Threads Hybrid Implementations

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

4 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) 5

Implementing Threads in User Space A user-level threads package 6 Pros of User Space Implementation Can be used in OSes which dont 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 7 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 8 Implementing Threads in the Kernel A threads package managed by the kernel 9

Kernel Space Pros: 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 10

Hybrid Implementations Multiplexing user-level threads onto kernel- level threads 11 Processes & Threads Resource ownership Process or Task Scheduling/execution Thread or lightweight process

One process, one thread (MS-DOS) Multiple processes, one thread per process (Unix) One process, multiple threads (Java Runtime) Multiple processes,

multiple threads (W2K, Solaris, Linux) 12 Single Threaded and Multithreaded Process Models 13 Key Benefits of Threads

14 User and Kernel-Level Threads Performance 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 Null fork Signal Wait ULT KLT Process 34 948 11,300 37 441 1,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. 15

Recently Viewed Presentations

  • Wireless ATM networks - 123seminarsonly.com

    Wireless ATM networks - 123seminarsonly.com

    Wireless ATM networks new architecture elements and functionality supporting mobility * * Service scenarios wireless LAN networks with dynamically modified structure broadband wireless access networks wireless point-to-point links * Possible R&D directions GSM System + multimedia support QoS support ATM...
  • Classroom Strategies for English Medium Teaching and Learning

    Classroom Strategies for English Medium Teaching and Learning

    Tahoma MS PGothic Arial Calibri 新細明體 Wingdings Verdana 微軟正黑體 Wingdings 2 Office Theme 1_Office Theme 2_Office Theme Classroom Strategies for English Medium Teaching and Learning Our class's strategy We have only 75 minutes! Much of what I say today…
  • Sentence Structure, Grammar, and Mechanics Made Easy

    Sentence Structure, Grammar, and Mechanics Made Easy

    Here are a couple tricks to remember for writing strong sentences. Start Fast: state the subject and verb early in the sentence. This ensures that you use passive voice. It also allows you to focus more on the verb and...
  • Scenario-based Planning to IEPD Development

    Scenario-based Planning to IEPD Development

    What is a NIEM IEPD? Documentation and specification for describing NIEM information exchanges. Contains: Set of NIEM conforming XML schemas that (Re)use or correctly extend NIEM components. Define a class of XML exchange instances. Documentation detailing How to implement the...
  • Membrane Separations & System Technologies and Case Studies

    Membrane Separations & System Technologies and Case Studies

    2.85 mg/L Projected Energy Costs - 24,000 bbl/day (3,790 m3/d) Cost for a 3-pass system $ 1.85M USD Total Energy - 720 hp $ .0422/bbl Based on an electric cost of $0.08/kwh USD (equal to $0.317 m3/d) Operating Costs $...
  • Tom and Jerry - University of Florida

    Tom and Jerry - University of Florida

    EEL-5666: Intelligent Machines Design Lab Overview Overall Function Tom's Design Jerry's Design Special Sensor - RF Link Conclusions Possible Improvements Questions EEL-5666: Intelligent Machines Design Lab Overall Function Jerry and Tom simulate a Predator / Prey Model. Jerry is the...
  • Ocean Fall final exam review - PC\|MAC

    Ocean Fall final exam review - PC\|MAC

    Ocean Fall final exam review. 2013. How does sea floor spreading effect the age and density of ocean granite? ... Primitive Sharks Eye Ovoviviparous Fish Caudal Fin Vertebrates Pelvic Fin Speed. Stop ChondrichthyesOviparous. ...
  • Why did Britain retreat from its empire? Reason 4 - The Suez ...

    Why did Britain retreat from its empire? Reason 4 - The Suez ...

    Did Britain decolonise because of the Suez Canal Crisis? C aim - to explain how the Suez Canal Crisis made Britain decolonise B aim - to explain both sides and give a judgement A aim - to explain both sides...