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...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help