File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 1
1
#include < fmt/format.h>
2
+ #include < atomic>
2
3
#include < functional>
3
4
#include < memory>
4
5
#include < numeric>
@@ -108,10 +109,31 @@ TEST(TrieStoreTest, MixedConcurrentTest) {
108
109
threads.push_back (std::move (t));
109
110
}
110
111
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
+
111
127
for (auto &t : threads) {
112
128
t.join ();
113
129
}
114
130
131
+ stop->store (true );
132
+
133
+ for (auto &t : read_threads) {
134
+ t.join ();
135
+ }
136
+
115
137
// verify final trie
116
138
for (uint32_t i = 0 ; i < keys_per_thread * 4 ; i++) {
117
139
std::string key = fmt::format (" {:#05}" , i);
You can’t perform that action at this time.
0 commit comments