예제 #1
0
파일: main.cpp 프로젝트: ale3otik/ADS-4
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;
}
예제 #2
0
파일: test.cpp 프로젝트: egiby/mipt_algo
void getPush(SyncQueue<ui32> &queue, ui32 x)
{
    std::lock_guard<SyncQueue<ui32> > l(queue);
    queue.push(x);
}
예제 #3
0
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]);
    }
}
예제 #4
0
void pushElem(int num) {
    sync_queue.push(num);
}
예제 #5
0
TEST(SyncQueue, ClosedExceptions) {
    SyncQueue<std::queue<int>> syncQueue;
    syncQueue.close();
    ASSERT_THROW(syncQueue.close(), closedQueueException);
    ASSERT_THROW(syncQueue.push(0), closedQueueException);
}