Skip to content

Commit

Permalink
p0: test concurrent put/get in mixed test (#598)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Chi <[email protected]>
  • Loading branch information
skyzh committed Aug 29, 2023
1 parent 735cab3 commit 606ef85
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/primer/trie_store_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <fmt/format.h>
#include <atomic>
#include <functional>
#include <memory>
#include <numeric>
Expand Down Expand Up @@ -108,10 +109,31 @@ TEST(TrieStoreTest, MixedConcurrentTest) {
threads.push_back(std::move(t));
}

std::vector<std::thread> read_threads;
std::shared_ptr<std::atomic_bool> stop = std::make_shared<std::atomic_bool>(false);

for (int tid = 0; tid < 4; tid++) {
std::thread t([&store, tid, stop] {
uint32_t i = 0;
while (!stop->load()) {
std::string key = fmt::format("{:#05}", i * 4 + tid);
store.Get<std::string>(key);
i = (i + 1) % keys_per_thread;
}
});
read_threads.push_back(std::move(t));
}

for (auto &t : threads) {
t.join();
}

stop->store(true);

for (auto &t : read_threads) {
t.join();
}

// verify final trie
for (uint32_t i = 0; i < keys_per_thread * 4; i++) {
std::string key = fmt::format("{:#05}", i);
Expand Down

0 comments on commit 606ef85

Please sign in to comment.