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 4 of 6

Java lazy init: the missing volatile

builds on: Race conditions and interleavings
The agent wrote double-checked locking: check `inst`, lock, check again, create. The tell: the first read of `inst` is outside the lock, and the field is not `volatile`. Another thread can see a non-null `inst` before the constructor's writes are visible to it, so its fields are still null or zero. Later cost: rare NullPointerExceptions or wrong defaults in production that no test reproduces. BETTER: make `inst` `volatile`; a thread that reads it then also sees the constructor's writes. Or use a holder class: the JVM initialises a class once, thread-safely, on first use.
// Java
// BAD: plain field
private static Svc inst;
static Svc get() {
  if (inst == null) {
    synchronized (L.class) {
      if (inst == null) inst = new Svc();
    }
  }
  return inst;
}
// BETTER: same get(), field made volatile
private static volatile Svc inst;
Terms on this card
lazy init
Creating an object only the first time it is needed, instead of at startup.
double-checked locking
Checking a field for null, then locking and checking again before creating it. In Java it is only correct if the field is `volatile`.
volatile
A Java field modifier. Writes to the field become visible to other threads. A thread that reads a reference from it also sees everything written before it was set, such as the constructor's work.
holder class
A Java idiom: a nested static class holds the instance. The JVM initialises that class once, thread-safely, on first use.
JVM
Java Virtual Machine: the runtime that runs Java bytecode and guarantees, among other things, that each class is initialised exactly once.
Learn this step by step on Bytewise
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