void test_queue() { SyncQueue<int> q; const int nthreads = 10; const int64_t qsize = 100; vector<thread> threads; for (int i = 1 ; i < qsize + 1; ++i) { q.push(i); } vector<int> qnt(nthreads); for(int i = 0; i < nthreads; ++i) { qnt[i] = 0; int limit = qsize / nthreads; threads.push_back(thread(test_queue_thread<int>, &q, &(qnt[i]), limit)); } for(auto & x : threads) { x.join(); } int64_t sum = 0; for(int i = 0; i < nthreads; ++i) { sum += qnt[i]; } assert(sum == ((qsize * (qsize+1)) / 2)); cout << "queue works" << endl; }
void getPush(SyncQueue<ui32> &queue, ui32 x) { std::lock_guard<SyncQueue<ui32> > l(queue); queue.push(x); }
void sender(std::vector<int> &source, SyncQueue<C> &taskQueue, size_t offset, size_t size) { auto upperBound = std::min(offset + size, source.size()); for (size_t i = offset; i < upperBound; ++i) { taskQueue.push(source[i]); } }
void pushElem(int num) { sync_queue.push(num); }
TEST(SyncQueue, ClosedExceptions) { SyncQueue<std::queue<int>> syncQueue; syncQueue.close(); ASSERT_THROW(syncQueue.close(), closedQueueException); ASSERT_THROW(syncQueue.push(0), closedQueueException); }