Am Do., 29. Nov. 2018 um 19:43 Uhr schrieb Johannes Waldmann <johannes.waldmann@htwk-leipzig.de>:
I am surprised by the behaviour of the program below
(the interesting property is whether it will output "foo").

Behaviours (plural) actually: it seems to depend
on optimisation level, on omit-yields,
and on very small changes in the source code: [...]

IMHO there is nothing very surprising here: You have 2 threads with no synchronization between them whatsoever, so you get what you deserve: Undefined behavior. :-) This is the behavior you get in basically all programming languages/execution environments I know of, *unless* they make a very strong guarantee about their scheduling behavior (whichis very rare, for good reasons). Do we have such a guarantee somewhere in the GHC/base documentation? I don't think so, but if we had, I would be interested to see a reference to that.

Cheers,
   S.