diff options
author | ayles <ayles@yandex-team.com> | 2022-09-19 12:27:43 +0300 |
---|---|---|
committer | ayles <ayles@yandex-team.com> | 2022-09-19 12:27:43 +0300 |
commit | ff49fbec3c655b16509b12a0f3a82efacd521771 (patch) | |
tree | e14ab4fda50eaf34e8f2c2be86ab2cb055eb96e2 /library/cpp | |
parent | 94de3c44fbfb54ffa1ea7a8baa73d174ee6f40b1 (diff) | |
download | ydb-ff49fbec3c655b16509b12a0f3a82efacd521771.tar.gz |
Fix tsan warnings in yt intrusive ptr
For example, https://github.com/google/sanitizers/issues/1352 - tsan is not working well with std::atomic_thread_fence
Minimal reproducible example (and one that bothers most in every fiber-aware service):
```
auto threadPool = NYT::New<NYT::NConcurrency::TThreadPool>(2, "thread");
TVector<NYT::TFuture<void>> futures;
for (size_t i = 0; i < 100000; ++i) {
futures.emplace_back(BIND([]() {
}).AsyncVia(threadPool->GetInvoker()).Run());
}
for (auto& future : futures) {
future.Get().ThrowOnError();
}
```
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/yt/memory/ref_counted-inl.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/library/cpp/yt/memory/ref_counted-inl.h b/library/cpp/yt/memory/ref_counted-inl.h index 1ad7433ca93..bb29f70585d 100644 --- a/library/cpp/yt/memory/ref_counted-inl.h +++ b/library/cpp/yt/memory/ref_counted-inl.h @@ -4,6 +4,8 @@ #include "ref_counted.h" #endif +#include <util/system/sanitizers.h> + namespace NYT { //////////////////////////////////////////////////////////////////////////////// @@ -97,6 +99,7 @@ Y_FORCE_INLINE bool TRefCounter::Unref(int n) const YT_ASSERT(oldStrongCount >= n); if (oldStrongCount == n) { std::atomic_thread_fence(std::memory_order_acquire); + NSan::Acquire(&StrongCount_); return true; } else { return false; @@ -120,6 +123,7 @@ Y_FORCE_INLINE bool TRefCounter::WeakUnref() const YT_ASSERT(oldWeakCount > 0); if (oldWeakCount == 1) { std::atomic_thread_fence(std::memory_order_acquire); + NSan::Acquire(&WeakCount_); return true; } else { return false; |