Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Races introduced by plausible concurrent code
card 6 of 6
Wrong between the lines, not on them
builds on: Race conditions and interleavings
Concurrent code can read fine line by line and still be wrong between the lines. Look for two things:
- shared state that goroutines, threads or async callbacks touch without a lock, an atomic call or a single owner;
- a check or read separated from its act or write.
For data races, run the race detector where one exists (`go test -race`) on a test that runs the code concurrently. Race detectors stay silent on logical races, so your review is the check.
Terms on this card
- go test -race
- Runs Go tests with the race detector. It reports unsynchronized conflicting memory accesses that occur during that run.
- race detector
- A tool that watches a running program and reports memory accesses from different threads that no synchronization orders. It finds data races, not logical races.
- atomic
- Happening as one indivisible step that no other thread can observe half-done or interleave with.
- go test
- The Go command that builds packages and runs their tests; './...' means the package and all below it.
- race
- A bug where the result depends on which concurrent task happens to run first.
Lesson goal: Recognise races that look fine on the page: a Go map written from goroutines, unsynchronized lazy initialisation in Java, check-then-act on a cache, and async read-modify-write in JS. Name which tool or synchronization would catch or fix each one. ·
the whole lesson