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.
Race conditions and interleavings card 2 of 6

Steps interleave in orders you didn't pick

Threads run as an **interleaving**: the scheduler can mix each thread's steps in any order. `count += 1` is really three steps: read, add, write. If two threads both read 41, both write 42, and one increment is lost. Most interleavings are harmless, so tests usually pass. The agent sees one green run and treats it as success. **Later cost:** counts, balances or stock levels silently wrong under real load.
Terms on this card
interleaving
One possible order in which the steps of several concurrently running threads end up mixed together. The scheduler may pick any of them.
scheduler
The part of the operating system or language runtime that decides which thread runs next and when to switch between threads.
green
A test or check that passes.
pass
Python statement that does nothing; used as a body, it makes a function or handler an empty shell.
Learn this step by step on Bytewise
Lesson goal: Explain how concurrent code can interleave and produce wrong results, using check-then-act and read-modify-write as examples. Distinguish a data race from a logical race, and explain why only synchronization (locks, atomics, channels) creates ordering while timing does not. · the whole lesson