Hacker News new | past | comments | ask | show | jobs | submit login

What sort of an interleaving would produce 1? Seems provably impossible to me, assuming atomic assignments.





I took another look, and AFAICT you're right. The best I can do is get the value 2:

* Run procedure P into its first iteration, stopping after temp is assigned "n + 1", or the value 1

* Run procedure Q through nine iterations, stopping after the ninth has completed (n changes, but who cares?)

* Run the next line of procedure P's first iteration, so that it assigns temp's value of 1 to n; n is now 1

* Run procedure Q into its tenth iteration, stopping after temp is assigned the value 2

* Complete procedure P (n changes, but who cares?)

* Complete procedure Q, so that n is assigned the value of temp, or 2.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: