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
- Output and formatting Out's buffer, Fmt's arguments, formatting into a Buf, and laying out columns.
- Strings and bytes Copying, hashing and ordering strings, searching bytes many at a time, and reading and writing binary formats.
- Lists, arrays, maps and sorting List(T), Vec(T), Map(K, V) and Sort(T), put together in a word-frequency program.
- Files and the command line Whole files with Files, descriptors and directories with Sys, and options with Opt.
- Time, randomness and other programs Clocks, sleeping, random bytes, running a program with its output piped back, and signals.
- Writing an allocator Mem.Allocator is two procedures; make one over a fixed array, and one that counts.
Standing alone
- A program with no run time What is in an executable, what isn't, and how to see it.
- 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.
- Starting, ending, and signals What runs before main, what runs after, and how to wait for a signal.
- One module, one file per target Portable programs, the code that isn't, and how the compiler keeps them in step.
The machine
- Procedures in assembly code procedures: the convention, registers, labels, db for what the assembler doesn't know.
- System calls SYSCALL directly: the numbers, the arguments, negative errno, and a cat without a library.
- What the compiler makes raz -S, reading a listing, what a check costs and what check off removes.
Shared memory
- Volatile ^VOLATILE T: memory that something else may change, laid over with a record.
- Atomics XADD, XCHG and CAS; a compare-and-swap loop; a lock built from them.
- Ordering and publication Why a flag isn't enough, what FENCE and the atomics order, and the pattern that works.
- A lock-free stack CAS on pointers, a push loop that never blocks, and the ABA problem that makes pop harder.
- A ring buffer between threads A single-producer, single-consumer queue, put together from what the tour has covered.