Thread safety problem during generation