[PATCH] D21609: [tsan] Intercept libcxx __release_shared to avoid false positive with weak_ptrs and destructors in C++
Dmitry Vyukov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 24 14:09:09 PDT 2016
dvyukov accepted this revision.
dvyukov added a comment.
This revision is now accepted and ready to land.
LGTM if you agree to change acq_rel to release
================
Comment at: lib/tsan/rtl/tsan_interceptors_mac.cc:309
@@ +308,3 @@
+
+ if (__tsan_atomic64_fetch_add(&o->shared_owners, -1, mo_acq_rel) == 0) {
+ o->on_zero_shared();
----------------
Since we are reimplementing the whole function we can actually do better than the original. The problem (for tsan) with mo_acq_rel is that all threads synchronize with each other, while only the last thread needs to synchronize with all other threads. So I would suggest to do:
if (__tsan_atomic64_fetch_add(&o->shared_owners, -1, mo_release) == 0) {
Acquire(thr, pc, &o->shared_owners);
o->on_zero_shared();
if (__tsan_atomic64_fetch_add(&o->shared_weak_owners, -1, mo_release) == 0)
Acquire(thr, pc, &o->shared_weak_owners);
o->on_zero_shared_weak();
}
}
http://reviews.llvm.org/D21609
More information about the llvm-commits
mailing list