fix coredump in link_hashmap

This commit is contained in:
nroskill
2023-10-18 09:13:51 +00:00
committed by ob-robot
parent be0ebf3e09
commit 02ee2b981c
2 changed files with 54 additions and 2 deletions

View File

@ -311,9 +311,13 @@ public:
int64_t count() const { return node_count_.value(); } int64_t count() const { return node_count_.value(); }
Node* next(Node* node) { Node* next(Node* node) {
get_qsync().acquire_ref();
while(NULL != (node = next_node(node)) while(NULL != (node = next_node(node))
&& node->is_dummy_node()) && node->is_dummy_node()) {
; // add usleep for dummy node test
// usleep(1 * 1000 * 1000);
}
get_qsync().release_ref();
return node; return node;
} }
private: private:

View File

@ -353,6 +353,54 @@ TEST(TestObHashMap, Retire)
delete t; delete t;
} }
/*
TEST(TestObHashMap, Dummy)
{
struct Fn {
bool operator()(HashKey& key, HashValue* value) {
return true;
}
};
Fn fn;
bool stop = false;
constexpr int64_t THREAD_COUNT = 8;
constexpr int64_t DATA_COUNT_PER_THREAD = 81920;
Hashmap hm(2);
EXPECT_EQ(OB_SUCCESS, hm.init());
std::thread insert_threads[THREAD_COUNT];
int64_t current = 0;
for (auto i = 0; i < THREAD_COUNT; ++i) {
insert_threads[i] = std::thread([&]() {
HashKey key;
HashValue *val_ptr = nullptr;
while (ATOMIC_LOAD(&current) < THREAD_COUNT * DATA_COUNT_PER_THREAD) {
key.v_ = ATOMIC_FAA(&current, 1);
EXPECT_EQ(OB_SUCCESS, hm.create(key, val_ptr));
hm.revert(val_ptr);
val_ptr = nullptr;
}
});
}
std::thread foreach_threads[THREAD_COUNT];
for (auto i = 0; i < THREAD_COUNT; ++i) {
foreach_threads[i] = std::thread([&]() {
while (!stop) {
hm.for_each(fn);
}
});
}
for (auto i = 0; i < THREAD_COUNT; ++i) {
insert_threads[i].join();
}
hm.reset();
hm.purge();
ATOMIC_STORE(&stop, true);
for (auto i = 0; i < THREAD_COUNT; ++i) {
foreach_threads[i].join();
};
}
*/
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
testing::InitGoogleTest(&argc,argv); testing::InitGoogleTest(&argc,argv);