Need to emit a CAS loop. Fix shared memory declaration. Declare atomic ops with correct memory scope.