$s = $s + 1 +=====================================================+ | CPU | +--------------------------+--------------------------+ | thread 1 | thread 2 | +==========================+==========================+ | - ... | | | - copy $s into temp | | | - $s is locked | | | - copy $s into temp | | | - $s is unlocked | | | - add one to temp | | +--------------------------+--------------------------+ | | - ... | | | - copy $s into temp | | | - $s is locked | | | - copy $s into temp | | | - $s is unlocked | | | - add one to temp | | | - assign temp to $s | | | - $s is locked | | | - assign temp to $s | | | - $s is unlocked | | | - ... | +--------------------------+--------------------------+ | - assign temp to $s | | | - $s is locked | | | - assign temp to $s | | | - $s is unlocked | | | - ... | | +==========================+==========================+ => $s is wrong <=