Lock when modifiying callbacks to avoid race conditions.