generator: Acquire lock to prevent two parallel runs of the generator.