diff options
author | Matthew Brandyberry <mbrandy@us.ibm.com> | 2019-01-29 13:25:35 -0800 |
---|---|---|
committer | Facebook Github Bot <facebook-github-bot@users.noreply.github.com> | 2019-01-29 14:10:04 -0800 |
commit | 4f809397fda86cbac19cda8c06bc3ecadd68bbc9 (patch) | |
tree | 82ba6f26ee2e19eb92549690e70d63abb8256d63 /c10 | |
parent | 719134f3c30f72a9a42100129f6ff8e851208f3f (diff) | |
download | pytorch-4f809397fda86cbac19cda8c06bc3ecadd68bbc9.tar.gz pytorch-4f809397fda86cbac19cda8c06bc3ecadd68bbc9.tar.bz2 pytorch-4f809397fda86cbac19cda8c06bc3ecadd68bbc9.zip |
Fix compare_exchange_weak usage in weak_intrusive_ptr (#16302)
Summary:
In the case of spurious failure, refcount is not incremented -- which leads to underflow once all references are released.
This was discovered when exercising multiprocessing on ppc64le.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/16302
Differential Revision: D13845435
Pulled By: ezyang
fbshipit-source-id: 8e264fff9dca8152cb12617e3216d5e48acd9557
Diffstat (limited to 'c10')
-rw-r--r-- | c10/util/intrusive_ptr.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/c10/util/intrusive_ptr.h b/c10/util/intrusive_ptr.h index 806d958541..9f5e686927 100644 --- a/c10/util/intrusive_ptr.h +++ b/c10/util/intrusive_ptr.h @@ -576,7 +576,7 @@ class weak_intrusive_ptr final { // Return nullptr. return intrusive_ptr<TTarget, NullType>(NullType::singleton()); } - } while (target_->refcount_.compare_exchange_weak(refcount, refcount + 1)); + } while (!target_->refcount_.compare_exchange_weak(refcount, refcount + 1)); return intrusive_ptr<TTarget, NullType>(target_); } |