Can a Data Race Happen on a Single-Core Machine?
aoli.al·3h·
Discuss: Hacker News

1. The Question

I woke up wondering: Can a data race happen on a single-core machine?.

A data race occurs when a program contains two conflicting accesses (write/write or read/write) that are not ordered by a happens-before relationship. This is the definition from Java Language Specification.

My first instinct was to ask Claude. The answer I received confidently showed a counter++ example and called it a “data race.”

1// Thread 1
2counter++;  // Read counter, increment, write back
3
4// Thread 2
5counter++;  // If OS switches here mid-operation, data race occurs

and they explained:

If Thread 1 is interrupted between r…

Similar Posts

Loading similar posts...