| | |
| | | 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; |
| | |
| | | start = atoi(argv[1]); |
| | | end = atoi(argv[2]); |
| | | } |
| | | //LockFreeQueue<struct Item> *queue = QueueFactory::createQueue<struct Item> (key, qsize); |
| | | SHMQueue<struct Item> *queue = new SHMQueue<struct Item>(key, qsize); |
| | | //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]; |
| | | struct timespec timeout = {10, 0}; |
| | | int i = start; |
| | | item.pic = i; |
| | | item.info = i; |
| | | // item.pic = i; |
| | | // item.info = i; |
| | | //while((end == -1 || (i < end) ) && (queue->add(item)) ) { |
| | | while(!stop && (queue->push(item)) ) { |
| | | item.pic = i; |
| | | item.info = i; |
| | | |
| | | cout << "入队:" << item.pic << ", " << item.info << endl; |
| | | while(!stop ) { |
| | | // item.pic = i; |
| | | // item.info = i; |
| | | //item = i + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| | | sprintf(item, "(%d)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", i); |
| | | if(queue->push_timeout(item, &timeout)) |
| | | cout << "入队:" << item << endl; |
| | | else |
| | | break; |
| | | // cout << item.pic << endl; |
| | | |
| | | i++; |