Unit 2b – Virtual Processors (Threads)

Irreproducible Interrupt Moments

I/O Devices Introduced Two Problems

  1. Multiple active devices needed to cooperate with the CPU to provide services (e.g. read a disk block)

    • multiple active "sequential execution" streams, in the CPU and the controller

      • different from our original hardware model and the model presented by programming languages which was ONE sequential stream of instructions
    • communications with I/O devices is inherently asyncronous

  2. I/O controllers had varying response times and the CPU can not simply wait

    • needed to be able to "multitask", and overlap the request and the response
    • programs may need to be arbitrarily interrupted to respond to the controllers

Difficulties of Asynchronous Programming

 

Thread

UThread: A Simple Thread System for C

 

Example Program Using UThreads

Give up CPU if there's another thread that can run (i.e., pong())'

 

Give up CPU if there's another thread that can run (i.e., ping())

 

Give up CPU to wait for ping() to return and thus its thread to finish

 

Revisiting the Disk Read

Synchronous Disk Read Using Threads

Recall Asyncronous Disk Read

We wanted to do this, but couldn't because risk reads are asyncronous...


We implemented it this way in event-driven programming style...

Hiding Asynchrony with Threads

Now we can do this...


We implemented it this way using threads to hide asynchrony...

Implementing Threads: Some Questions

Data Structures

Thread Scheduling

Priority, Round-Robin Scheduling Policy

Preemption

Implementing Quantum Preemption

Summary