More Raz

The second tour, for the part of raz that sits close to the machine. It assumes you have taken Raz, Set, Go or know Pascal or C well enough not to need it.

It has four parts: The library, the modules every program reaches for; Standing alone, programs that need no C and no run time; The machine, procedures written in assembly and direct system calls; and Shared memory, volatile accesses, atomics and threads. Every program is compiled and run when this page is made, as before.

The library

  1. Output and formatting Out's buffer, Fmt's arguments, formatting into a Buf, and laying out columns.
  2. Strings and bytes Copying, hashing and ordering strings, searching bytes many at a time, and reading and writing binary formats.
  3. Lists, maps and sorting List(T), Map(K, V) and Sort(T), put together in a word-frequency program.
  4. Files and the command line Whole files with Files, descriptors and directories with Sys, and options with Opt.
  5. Time, randomness and other programs Clocks, sleeping, random bytes, and running a program with its output piped back.
  6. Writing an allocator Mem.Allocator is two procedures; make one over a fixed array, and one that counts.

Standing alone

  1. A program with no run time What is in an executable, what isn't, and how to see it.
  2. Threads without C, and keeping the two apart link static, what a module that makes its own system calls promises, and the error when it breaks.
  3. Starting, ending, and signals What runs before main, what runs after, and how to wait for a signal.
  4. One module, one file per target Portable programs, the code that isn't, and how the compiler keeps them in step.

The machine

  1. Procedures in assembly code procedures: the convention, registers, labels, db for what the assembler doesn't know.
  2. System calls SYSCALL directly: the numbers, the arguments, negative errno, and a cat without a library.
  3. What the compiler makes raz -S, reading a listing, what a check costs and what check off removes.

Shared memory

  1. Volatile ^VOLATILE T: memory that something else may change, laid over with a record.
  2. Atomics XADD, XCHG and CAS; a compare-and-swap loop; a lock built from them.
  3. Ordering and publication Why a flag isn't enough, what FENCE and the atomics order, and the pattern that works.
  4. A lock-free stack CAS on pointers, a push loop that never blocks, and the ABA problem that makes pop harder.
  5. A ring buffer between threads A single-producer, single-consumer queue, put together from what the tour has covered.