TAOCP Vol 1: Fundamental Algorithms · Week 48

TAOCP 1.4.4 Input and Output

Updated

About 4 hours19 exercises, rated 05 to 40

Summary

TAOCP 1.4.4 Input and Output: How MIX overlaps computation with slow I/O using buffers, including double buffering and buffer swapping, and the bookkeeping needed to do that safely. Budget about 4 hours; do exercises 1, 3 and 6.

Flashcards 14 cards for Anki and AnkiMobile · all decks

Anki deck.tsv

This week's steps

3 steps
  1. Read §1.4.4 Input and Output

    Draw the buffers as boxes and simulate a few steps of producer and consumer by hand.

  2. Work the exercises (8 picked)

    Start with Ex 1, Ex 3, Ex 6; log what you solve below.

  3. Write down one thing you'd explain to someone

    A few sentences in your own words in Your notes: the idea, why it works, an example. 30 words ticks this.

Sign in to track this: tick each step off and it counts toward your week.

Exercises

This section has 19 exercises, rated 05 to 40, and Knuth marks seven of them with the triangle for recommended. Mix of reasoning about buffer timelines and writing buffered MIX code. Exercise 17 is rated 40; skip it.

Worth your time

  • Exercise 105

    Check whether reordering the moves and the busy wait breaks buffered input.

    Discuss

  • Exercise 322▶ Recommended

    Write the buffer-swapping output routine, the mirror image of the input one.

    Discuss

  • Exercise 5M21▶ Recommended

    Bound how much buffering can speed up a program that uses several devices.

    Discuss

  • Exercise 612

    Set up the input routine so it gets off to the right start. Initialization is where buffering code breaks.

    Discuss

  • Exercise 921▶ Recommended

    Simulate a buffer timeline from a list of compute and I/O times.

    Discuss

  • Exercise 1420▶ Recommended

    What happens when a program grabs two buffers before releasing either.

    Discuss

  • Exercise 1522▶ Recommended

    Write a complete tape copy program with three buffers, as fast as possible.

    Discuss

  • Exercise 1830▶ Recommended

    Rework the buffering algorithms for a MIX with interrupts. The stretch.

    Discuss

Your log

Sign in to log the exercises you work: number, rating, how far you got.

Your notes

Only you

Sign in to keep private notes on this guide, in Markdown. They stay yours: never on your profile, and you can export them all.

Discussion

0 posts

Questions about the reading go here; each exercise has its own thread below. Hints over answers.

No posts yet. Ask a question or share a tip.

Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Exercise threads

One thread per exercise. Open one to ask for a nudge or check your thinking.

  • Exercise 105No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 322No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 5M21No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 612No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 921No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1420No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1522No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1830No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Reference

Why it matters

Buffering is still how fast I/O works, from disk reads to network sockets to audio. The ring-buffer patterns here are the same ones you will see in kernel and driver code.

Before you start
  • 1.4.1 Subroutines
How to approach it

Draw the buffers as boxes and simulate a few steps of producer and consumer by hand. Do not get hung up on MIX device details.

Common traps
  • Getting lost in tape and card-reader specifics. The ideas, not the devices, are the point.

Spot a mistake? Report it

Back to week 48