vbsd 2 months ago

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

  • dtgriscom 2 months ago

    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.