MCPcopy Create free account
hub / github.com/cameron314/readerwriterqueue / main

Function main

tests/stabtest/stabtest.cpp:19–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19int main(int argc, char** argv)
20{
21 // Disable buffering (so that when run in, e.g., Sublime Text, the output appears as it is written)
22 std::setvbuf(stdout, nullptr, _IONBF, 0);
23
24 std::printf("Running stability test for moodycamel::ReaderWriterQueue.\n");
25 std::printf("Logging to 'log.txt'. Press CTRL+C to quit.\n\n");
26
27
28 std::ofstream log("log.txt");
29
30 try {
31 for (unsigned int i = 0; true; ++i) {
32 log << "Test #" << i << std::endl;
33 std::printf("Test #%d\n", i);
34
35 ReaderWriterQueue<unsigned long long> q((rand() % 32) + 1);
36
37 SimpleThread writer([&]() {
38 for (unsigned long long j = 0; j < 1024ULL * 1024ULL * 32ULL; ++j) {
39 unpredictableDelay(500);
40 q.enqueue(j);
41 }
42 });
43
44 SimpleThread reader([&]() {
45 bool canLog = true;
46 unsigned long long element;
47 for (unsigned long long j = 0; j < 1024ULL * 1024ULL * 32ULL;) {
48 if (canLog && (j & (1024 * 1024 * 16 - 1)) == 0) {
49 log << " ... iteration " << j << std::endl;
50 std::printf(" ... iteration %llu\n", j);
51 canLog = false;
52 }
53 unpredictableDelay();
54 if (q.try_dequeue(element)) {
55 if (element != j) {
56 log << " ERROR DETECTED: Expected to read " << j << " but found " << element << std::endl;
57 std::printf(" ERROR DETECTED: Expected to read %llu but found %llu", j, element);
58 }
59 ++j;
60 canLog = true;
61 }
62 }
63 if (q.try_dequeue(element)) {
64 log << " ERROR DETECTED: Expected queue to be empty" << std::endl;
65 std::printf(" ERROR DETECTED: Expected queue to be empty\n");
66 }
67 });
68
69 writer.join();
70 reader.join();
71 }
72 }
73 catch (std::exception const& ex) {
74 log << " ERROR DETECTED: Exception thrown: " << ex.what() << std::endl;
75 std::printf(" ERROR DETECTED: Exception thrown: %s\n", ex.what());
76 }

Callers

nothing calls this directly

Calls 4

unpredictableDelayFunction · 0.85
joinMethod · 0.80
enqueueMethod · 0.45
try_dequeueMethod · 0.45

Tested by

no test coverage detected