Hacker News new | ask | show | jobs
by the8472 3276 days ago
How can you be sure that the other threads ever see it in time? they might be suspended for a whole second because a HDD needs to spin up or something like that.

So threads never seeing the value is already a valid outcome, so the compiler might as well always do that.

1 comments

time.Sleep(1000) could be replaced with a real syncing mechanism of some kind -- it's only for illustration.
a real syncing mechanism would introduce compiler barriers that prevent such an optimization.