aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/kernels/variable_ops.h
diff options
context:
space:
mode:
authorGravatar Alexandre Passos <apassos@google.com>2018-02-21 17:19:40 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-02-21 17:23:51 -0800
commit913323ba96034108c0c85cadbfd879b35858aa26 (patch)
tree978547771b3bb1629272c044640796ebfeda2881 /tensorflow/core/kernels/variable_ops.h
parentcb7ae9e5af12055bbb14284b0fd5e7d2ac292415 (diff)
Fix subtle race condition in ResourceVariable.is_initialized
PiperOrigin-RevId: 186544846
Diffstat (limited to 'tensorflow/core/kernels/variable_ops.h')
-rw-r--r--tensorflow/core/kernels/variable_ops.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/tensorflow/core/kernels/variable_ops.h b/tensorflow/core/kernels/variable_ops.h
index 83134bad37..8b406e5311 100644
--- a/tensorflow/core/kernels/variable_ops.h
+++ b/tensorflow/core/kernels/variable_ops.h
@@ -45,6 +45,14 @@ class Var : public ResourceBase {
tensor_.shape().DebugString());
}
+ // Only used in the resource variable path. In resource variables,
+ // tensor.IsInitialized() can be true (i.e. have memory allocated to it) while
+ // there is not a good value there due to a race condition, and it's possible
+ // to stumble upon this during variable.initialized_value(). So it's best to
+ // just store directly whether the variable is initialized.
+ bool is_initialized = false; // GUARDED_BY(mu_) but annotalysis doesn't like
+ // it.
+
private:
mutex mu_;
Tensor tensor_;