SanitizerTest/main.cc

36 lines
854 B
C++

#include <gtest/gtest.h>
#include <readerwriterqueue/readerwriterqueue.h>
#include <thread>
static constexpr size_t repeat = 1 << 20;
void producer(moodycamel::ReaderWriterQueue<std::string>& queue) {
std::string str{"10"};
for (int i = 0; i < repeat; ++i) {
while (!queue.try_enqueue(str)) {
std::this_thread::yield();
}
}
}
void consumer(moodycamel::ReaderWriterQueue<std::string>& queue) {
size_t counter = 0;
std::string val;
while (counter < repeat) {
while (!queue.try_dequeue(val)) {
std::this_thread::yield();
}
++counter;
}
}
TEST(BASIC, rwq) {
moodycamel::ReaderWriterQueue<std::string> queue;
std::jthread t1{&producer, std::ref(queue)};
std::jthread t2{&consumer, std::ref(queue)};
}
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}