int main() { vector<thread> threads; int n, m; cin >> n; for (int i = 0; i < n; i++) { if (i % 2 == 0) threads.push_back(thread(pushElem, i)); else threads.push_back(thread(popElem)); } for (int i = 0; i < n; i++) { threads[i].join(); } while(!sync_queue.empty()) { cout << sync_queue.front() << " "; sync_queue.pop(); } return 0; }
TEST_P(SyncQueueTest, TestOfPush) { SyncQueue<ui32> queue; std::thread threads[10]; for (ui32 i = 0; i < GetParam(); ++i) { threads[i % 10] = std::thread(getPush, std::ref(queue), i); if (i) threads[(i - 1) % 10].join(); } threads[(GetParam() - 1) % 10].join(); std::vector<ui32> used(GetParam()); for (ui32 i = 0; i < GetParam(); ++i) { used[queue.front()] = 1; queue.pop(); } ASSERT_EQ(std::accumulate(used.begin(), used.end(), 0), GetParam()); }