Thread and critical block codegen fixed