Use atomic access for flag variables