当前位置: 首页>>代码示例>>C++>>正文


C++ concurrent_queue::deQ方法代码示例

本文整理汇总了C++中concurrent_queue::deQ方法的典型用法代码示例。如果您正苦于以下问题:C++ concurrent_queue::deQ方法的具体用法?C++ concurrent_queue::deQ怎么用?C++ concurrent_queue::deQ使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在concurrent_queue的用法示例。


在下文中一共展示了concurrent_queue::deQ方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: worker

void* worker(void* d) {
    shared_ptr<UploadBuffer> pdata;
    srand(time(NULL));
    // get data from fq
    while (1) {
        fq.deQ(pdata);

        if (pdata->index == 0) {
            // inited data??
            cout << "inited data" << std::endl;
        }

        if (pdata->index == -1) {  //  finished
            // cout<<"finished"<<std::endl;
            break;
        }

        MD5Calc m;
        m.Update(pdata->data.getdata(), pdata->data.len());
        cout << pdata->index << "\t" << m.Get() << std::endl;
        // sleep(rand()%5);

        // reset pdata
        pdata->data.reset();
        pdata->index = 0;

        // re queue to empty queue
        eq.enQ(pdata);
    }
    // cout<<"quit...\n";
}
开发者ID:BenjaminYu,项目名称:gpdb,代码行数:31,代码来源:testq.cpp

示例2: while

void *worker(void *a) {
    int r;
    while (1) {
        q.deQ(r);
        if (r == -1) break;
    }
    return NULL;
}
开发者ID:jianlirong,项目名称:gps3ext,代码行数:8,代码来源:utils_test.cpp

示例3: main

int main(int argc, char* argv[]) {
    vector<pthread_t> threads;
    shared_ptr<UploadBuffer> curdata;

    if (argc < 2) {
        printf("not enough args\n");
        return 1;
    }

    int fd = open(argv[1], O_RDONLY);
    if (fd == -1) {
        perror("open file fail");
        return 1;
    }

    char* localbuf = (char*)malloc(READLEN);
    int readlen = READLEN;

    for (int tnum = 0; tnum < NUMTHREADS; tnum++) threads.emplace_back();

    for (int tnum = 0; tnum < NUMTHREADS; tnum++) {
        eq.enQ(make_shared<UploadBuffer>(CHUCKSIZE));
    }

    for (int tnum = 0; tnum < NUMTHREADS; tnum++) {
        pthread_create(&threads[tnum], NULL, worker, NULL);
    }

    eq.deQ(curdata);
    // assert (curdata->index == 0)
    int count = 1;
    curdata->index = count++;

    int tmplen;

    while (1) {
        // read data from file
        readlen = read(fd, localbuf, READLEN);
        if (readlen == -1) {
            perror("read fail");
            break;
        } else if (readlen == 0) {  // EOF
            // cout<<"end of file\n";
            if (curdata->index > 0) fq.enQ(curdata);
            break;
        }

        //
        while (1) {
            tmplen = curdata->data.append(localbuf, readlen);
            if (tmplen < readlen) {  // change to next queue, enqueue
                fq.enQ(curdata);
                eq.deQ(curdata);
                curdata->index = count++;

                // assert (curdata->index == 0)
                readlen -= tmplen;
            } else {
                break;  // contineu to read
            }
        }
    }

    printf("Start teardown\n");

    // terminate thread
    for (int tnum = 0; tnum < NUMTHREADS; tnum++) {
        eq.deQ(curdata);
        curdata->index = -1;
        fq.enQ(curdata);
    }
    curdata.reset();
    for (int tnum = 0; tnum < NUMTHREADS; tnum++) {
        pthread_join(threads[tnum], NULL);
    }

    free(localbuf);
    close(fd);
    return 0;
}
开发者ID:BenjaminYu,项目名称:gpdb,代码行数:80,代码来源:testq.cpp


注:本文中的concurrent_queue::deQ方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。