From 37a7bd95042c19d7334b099d50ac6dc8e07e4b4e Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期二, 07 七月 2020 16:40:51 +0800 Subject: [PATCH] update --- test/multiple_queue_productor.c | 23 ++++++++++++----------- 1 files changed, 12 insertions(+), 11 deletions(-) diff --git a/test/productor.c b/test/multiple_queue_productor.c similarity index 71% rename from test/productor.c rename to test/multiple_queue_productor.c index 66cb0bb..9e7c0e9 100644 --- a/test/productor.c +++ b/test/multiple_queue_productor.c @@ -3,11 +3,13 @@ using namespace std; - +#define NTHREADS 4 +struct Targ targs[NTHREADS]; +size_t qsize = 16; void sigint_handler(int sig) { cerr << "sigint_handler" << endl; - destroy(); + mm_destroy(); exit(0); } @@ -17,9 +19,10 @@ struct Targ * targ = (struct Targ * )arg; // cerr << "productor key="<<targ->key << endl; err_msg(0, "productor key = %d\n", targ->key ); - SLinkedLockFreeQueue<struct Item> *queue = QFactory::createLinkedLockFreeQueue<struct Item> (targ->key, 10); + //SLinkedLockFreeQueue<struct Item> *queue = QFactory::createLinkedLockFreeQueue<struct Item> (targ->key, 10); //SArrayLockFreeQueue<struct Item> *queue = QFactory::createArrayLockFreeQueue<struct Item> (targ->key, 10); - + + LockFreeQueue<struct Item> *queue = QueueFactory::createQueue<struct Item> (targ->key, qsize); /* Transfer blocks of data from stdin to shared memory */ int end = targ->end; struct Item item; @@ -29,12 +32,10 @@ item.pic = i; item.info = i; - while((end == -1 || (i < end) ) && (queue->add_timeout(item, &timeout)) ) { + while((end == -1 || (i < end) ) && (queue->push(item)) ) { item.pic = i; item.info = i; - - // cout << "鍏ラ槦锛�" << item.pic << ", " << item.info << endl; - //cout << item.pic << endl; + printf("productor(%d) 鍏ラ槦锛歿%d, %d}\n", targ->key, item.pic, item.info); i++; @@ -54,7 +55,7 @@ int i; pthread_t tids[NTHREADS]; void *res[NTHREADS]; - struct Targ targs[NTHREADS]; + for (i = 0; i< NTHREADS; i++) { @@ -64,14 +65,14 @@ targs[i].end = 100000; pthread_create(&tids[i], NULL, run, (void *)&targs[i]); - sleep(1); + //sleep(1); } for (i = 0; i< NTHREADS; i++) { if(pthread_join(tids[i], &res[i])!=0) { perror("productor pthread_join"); } else { - fprintf(stderr, "productor %d 鍐欏叆 %ld 鏉℃暟鎹甛n", i, (long)res[i]); + fprintf(stderr, "productor(%d) 鍐欏叆 %ld 鏉℃暟鎹甛n", i, (long)res[i]); } } -- Gitblit v1.8.0