ST
StateTrace
Visual Quant & Low-Latency Systems Lab
GitHub
Concepts/Synchronization/Race Condition

Race Condition

The same read–compute–write bug class in three domains. Bank balance loses a withdrawal. Lazy initialization leaks an allocation. Ticket booking double-books a seat. Same shape, different surface.

Steps
1/12
Stateshared + per-thread
T1
T1 local
statusidle
observed
allocated
returned
shared
shared memoryread
instancenullptr
heap.objects0
counter per stepnow = 0
T2
T2 local
statusidle
observed
allocated
returned
Race conditions are a bug class. Correctness, not latency, is the measurement.
OBSERVED

instance is nullptr. Heap holds zero Singleton objects.

Lazy Initialization
1Singleton* instance = nullptr;
2
3Singleton* get_singleton() {
4    if (instance == nullptr) {     // check
5        instance = new Singleton();// allocate + publish
6    }
7    return instance;
8}
Historystep 1 / 12
step 1/12
Same race shape, different surface. Walk the other two for the full pattern.