Lock mechanism to enable atomic updates to shared memory