Lock mechanism that enables atomic updates to shared memory