Commit c5f46707 authored by Maged Michael's avatar Maged Michael Committed by Facebook Github Bot

hazptr: Add test to detect no reclamation, without calling cleanup.

Summary: Add test to detect no reclamation (without calling hazptr_cleanup). The test retires a number of objects that would trigger bulk reclamation. One or more objects are expected be reclaimed. The number of retired objects must be greater than or equal to hazptr_domain::kThreshold to expect reclamation to happen.

Reviewed By: yfeldblum

Differential Revision: D8849957

fbshipit-source-id: ef590af21a55348ed0ed72be3637853eceb21cbc
parent 0b1134d2
......@@ -33,6 +33,14 @@
namespace folly {
namespace detail {
constexpr int hazptr_domain_rcount_threshold() {
return 1000;
}
} // namespace detail
/**
* hazptr_domain
*
......@@ -42,7 +50,7 @@ namespace folly {
*/
template <template <typename> class Atom>
class hazptr_domain {
static constexpr int kThreshold = 1000;
static constexpr int kThreshold = detail::hazptr_domain_rcount_threshold();
static constexpr int kMultiplier = 2;
static constexpr uint64_t kSyncTimePeriod{2000000000}; // nanoseconds
......
......@@ -1078,6 +1078,25 @@ TEST(HazptrTest, dsched_wide_cas) {
wide_cas_test<DeterministicAtomic>();
}
TEST(HazptrTest, reclamation_without_calling_cleanup) {
c_.clear();
int nthr = 5;
int objs = folly::detail::hazptr_domain_rcount_threshold();
std::vector<std::thread> thr(nthr);
for (int tid = 0; tid < nthr; ++tid) {
thr[tid] = std::thread([&, tid] {
for (int i = tid; i < objs; i += nthr) {
auto p = new Node<>;
p->retire();
}
});
}
for (auto& t : thr) {
t.join();
}
ASSERT_GT(c_.dtors(), 0);
}
// Benchmark drivers
template <typename InitFunc, typename Func, typename EndFunc>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment