Live data from Hacker News

Race Conditions Can Be Useful for Parallelism

shwestrick.github.io

71–72 of 72 posts

Re: Race Conditions Can Be Useful for Parallelism

#71
post #26

Earlier quoted context omitted.

I think you missed the point. Let me expand. I mean, yes, what you say is true, but it just amounts to saying "synchronization is a solvable problem". At their core, ALL synchronization paradigms (spin polling, interrupt masking, OS-managed process suspend, hardware memory barriers, weird lockless tricks like Dekker's algorithm, you name it) can be understood to be ways of enforcing "para-determinism" on environments…

If you can't observe the non-determinism, then is it really non-determinism? Your processor executes a single thread of instructions also in a non-deterministic order, based on complex internal state. We'd never say it was non-deterministic, as you can't detect it.

You can absolutely observe non-determinism. That's what a race condition bug is, after all. You can also observe benign nondeterminism every day in anything that records ordering. Go do a parallel make, then do it again and observe the ordering of the mtime values in the intermediate artifacts. It won't be the same.

And FWIW: CPU-internal instruction reordering is observable too, though the details there get complicated. x86 hides (almost!) all the complexity from you, but ARM's OOO is leakier and requires careful attention to memory barriers.

Re: Race Conditions Can Be Useful for Parallelism

#72
post #45

Earlier quoted context omitted.

Java’s primitives and references are guaranteed to be “tear-free”, which guarantees no “out-of-thin-air” values. So a field set to 1 and being written by several threads to 2 and 3 can only ever be observed as 1,2 or 3, no other value. Is that what you mean under not catching fire?

> Java’s primitives and references are guaranteed to be “tear-free”, which guarantees no “out-of-thin-air” values Tear-free does not imply no out-of-thin-air. But, afaik, the java memory model protects from both tearing and oota.

Yeah, you are right, I was not clear in my wording.
Post reply on HN