add a mutex around the use of "check then act" code