Skip to content

Commit 606ef85

Browse files
authored
p0: test concurrent put/get in mixed test (#598)
Signed-off-by: Alex Chi <[email protected]>
1 parent 735cab3 commit 606ef85

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/primer/trie_store_test.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <fmt/format.h>
2+
#include <atomic>
23
#include <functional>
34
#include <memory>
45
#include <numeric>
@@ -108,10 +109,31 @@ TEST(TrieStoreTest, MixedConcurrentTest) {
108109
threads.push_back(std::move(t));
109110
}
110111

112+
std::vector<std::thread> read_threads;
113+
std::shared_ptr<std::atomic_bool> stop = std::make_shared<std::atomic_bool>(false);
114+
115+
for (int tid = 0; tid < 4; tid++) {
116+
std::thread t([&store, tid, stop] {
117+
uint32_t i = 0;
118+
while (!stop->load()) {
119+
std::string key = fmt::format("{:#05}", i * 4 + tid);
120+
store.Get<std::string>(key);
121+
i = (i + 1) % keys_per_thread;
122+
}
123+
});
124+
read_threads.push_back(std::move(t));
125+
}
126+
111127
for (auto &t : threads) {
112128
t.join();
113129
}
114130

131+
stop->store(true);
132+
133+
for (auto &t : read_threads) {
134+
t.join();
135+
}
136+
115137
// verify final trie
116138
for (uint32_t i = 0; i < keys_per_thread * 4; i++) {
117139
std::string key = fmt::format("{:#05}", i);

0 commit comments

Comments
 (0)