diff --git a/paddle/fluid/operators/recurrent_op.cc b/paddle/fluid/operators/recurrent_op.cc index 5ec7587b700bbe7931e639701685f7fc3c0c762a..c1adaf2037a34794218368ad46563efaca24e2ba 100644 --- a/paddle/fluid/operators/recurrent_op.cc +++ b/paddle/fluid/operators/recurrent_op.cc @@ -197,7 +197,6 @@ void RecurrentOp::RunImpl(const framework::Scope &scope, auto &dev_ctx = *pool.Get(place); VLOG(3) << "Static RNN input sequence length = " << seq_len; - StepScopes scopes = CreateStepScopes(dev_ctx, scope, seq_len); auto reverse = Attr(kReverse); framework::Executor executor(place); @@ -208,6 +207,13 @@ void RecurrentOp::RunImpl(const framework::Scope &scope, *program, block->ID(), Attr>( kSkipEagerDeletionVars) /*skip_ref_cnt_vars*/); + static std::mutex mutex; + std::lock_guard lock(mutex); + StepScopes scopes = CreateStepScopes(dev_ctx, scope, seq_len); + // TODO(gfwm2013) Function CreateStepScopes would make segmentation fault in + // multithreading in eval process, so we use a mutex before function + // CreateStepScopes to make sure that the computing process is correct. This + // problem will fix in next pull request. for (size_t i = 0; i < seq_len; ++i) { size_t seq_offset = reverse ? seq_len - i - 1 : i; VLOG(3) << "Recurrent operate at the time step " << seq_offset;