r/ProgrammerHumor • • Jan 02 '22

Debugging Code Be Like.

58.4k Upvotes

283 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Jan 02 '22

[deleted]

1

u/Hexorg Jan 02 '22

What if second thread checks out the value before first one commits it? That’s data race.

0

u/[deleted] Jan 02 '22

[deleted]

9

u/Hexorg Jan 02 '22

It’s a bit hard to explain because any race condition depends on accessing shared state which is a data race. But you can have both threads waiting to check out data, and even though the signaling around the data being checked out is correct (no data race) the logic is still just waiting forever (race condition).

For example one thread safely scans an array and outputs indexes that need to be removed while the other thread removes array items. Without copying the data, the first thread needs proper signaling to know when an index is removed so array length is now shorter.

0

u/[deleted] Jan 03 '22

[deleted]

→ More replies (0)