void runNeverFailUntilThread(int numThreads, int n, /*numOps*/ MPMCQueue<int, Atom, Dynamic>& cq, std::atomic<uint64_t>& sum, int t) { uint64_t threadSum = 0; for (int i = t; i < n; i += numThreads) { // enq + deq auto soon = Clock::now() + std::chrono::seconds(1); EXPECT_TRUE(cq.tryWriteUntil(soon, i)); int dest = -1; EXPECT_TRUE(cq.readIfNotEmpty(dest)); EXPECT_TRUE(dest >= 0); threadSum += dest; } sum += threadSum; }
void testTimeout(MPMCQueue<int, std::atomic, Dynamic>& q) { CHECK(q.write(1)); /* The following must not block forever */ q.tryWriteUntil( std::chrono::system_clock::now() + std::chrono::microseconds(10000), 2); }