From f75a37444e7a97fb58439077eea4d1b3c576bfe3 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期一, 20 七月 2020 11:17:33 +0800 Subject: [PATCH] update --- test/single_productor.c | 61 +++++++++++++++++++----------- 1 files changed, 38 insertions(+), 23 deletions(-) diff --git a/test/single_productor.c b/test/single_productor.c index 66633a8..819e10a 100644 --- a/test/single_productor.c +++ b/test/single_productor.c @@ -2,20 +2,22 @@ using namespace std; - - +int key = 1; +bool stop = false; void sigint_handler(int sig) { - cerr << "sigint_handler" << endl; - destroy(); - exit(0); - + printf("sigint_handler\n"); + stop = true; } int main(int argc, char *argv[]) -{ - void *shmp; +{ + + string line; signal(SIGINT, sigint_handler); + int qsize = 16; + + /* Create set containing two semaphores; initialize so that writer has first access to shared memory. */ int start = 0; @@ -25,28 +27,41 @@ start = atoi(argv[1]); end = atoi(argv[2]); } - //SAbstractQueue<struct Item> *queue = QFactory::createQueue<struct Item> (1, 10); - SLinkedLockFreeQueue<struct Item> *queue = QFactory::createLinkedLockFreeQueue<struct Item> (1, 10); + + mm_init(512); + //LockFreeQueue<item_t> *queue = QueueFactory::createQueue<item_t> (key, qsize); + SHMQueue<item_t> *queue = new SHMQueue<item_t>(key, qsize); /* Transfer blocks of data from stdin to shared memory */ - struct Item item; - struct timespec timeout = {5, 0}; + //item_t item; + //char item[1024]; + item_t item; + struct timespec timeout = {10, 0}; int i = start; - item.pic = i; - item.info = i; - //while((end == -1 || (i < end) ) && (queue->add(item)) ) { - while((queue->add(item)) ) { - item.pic = i; - item.info = i; - - // cout << "鍏ラ槦锛�" << item.pic << ", " << item.info << endl; - cout << item.pic << endl; + // item.pic = i; + // item.info = i; + while(!stop && (end == -1 || (i < end) ) ) { + //while(!stop ) { + // item.pic = i; + // item.info = i; + //item = i + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + //sprintf(item, "(%d)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", i); + if(queue->push(i)) + //cout << "鍏ラ槦锛�" << item << endl; + LoggerFactory::getLogger().error("%d", i); + // err_msg(0, "%d", i); + else { + break; + } + // cout << item.pic << endl; i++; } - destroy(); - cerr << "productor quit" << endl; + + //delete queue; + //mm_destroy(); + err_msg(0, "productor quit"); exit(EXIT_SUCCESS); } -- Gitblit v1.8.0