A data race is two threads touching the same memory at the same time, at least one of them writing, with nothing ordering them. In C++ it is undefined behavior. The everyday symptom is a lost update: balance_ += cents reads the balance, adds and writes it back, and if another thread writes in between, one deposit disappears.
A std::mutex makes a block of code exclusive: m.lock() waits until no other thread holds the mutex, and m.unlock() lets the next one in. Three rules make it work: every access to the shared data holds the same mutex, reads included (a reader can otherwise see half an update); the mutex lives next to the data it protects; and a decision and the action it leads to ("enough left? then take it") happen under one lock, not two.
This lesson calls lock() and unlock() by hand; the next one replaces them with guards that cannot forget.
Threads here are simulated. Your program runs on one real thread while a scheduler switches between your threads at shared reads and writes, locks, atomic operations, waits, yields and sleeps, and every test runs under 12 different schedules. The order things can happen in, races at those points and deadlocks are faithful. Real parallel speed-up and weak memory-order effects are not.
The read-modify-write happens while no other thread can touch balance_.