| | |
| | | using namespace std; |
| | | |
| | | |
| | | |
| | | int key = 1; |
| | | |
| | | void sigint_handler(int sig) { |
| | | destroy(); |
| | | destroy(key); |
| | | exit(0); |
| | | |
| | | } |
| | | int main(int argc, char *argv[]) |
| | | { |
| | | |
| | | int qsize = 16; |
| | | |
| | | void *shmp; |
| | | signal(SIGINT, sigint_handler); |
| | | /* Get IDs for semaphore set and shared memory created by writer */ |
| | | //SAbstractQueue<struct Item> *queue = QFactory::createQueue<struct Item> (1, 10); |
| | | SLinkedLockFreeQueue<struct Item> *queue = QFactory::createLinkedLockFreeQueue<struct Item> (1, 10); |
| | | |
| | | LockFreeQueue<struct Item> *queue = QueueFactory::createQueue<struct Item> (key, qsize); |
| | | /* Transfer blocks of data from shared memory to stdout */ |
| | | |
| | | struct timespec timeout = {10, 0}; |
| | | struct Item item; |
| | | while(queue->remove(item)) { |
| | | while(queue->pop(item)) { |
| | | |
| | | cout << item.pic << endl; |
| | | //sleep(1); |
| | | } |
| | | |
| | | destroy(); |
| | | destroy(key); |
| | | cerr << "consumer quit" << endl; |
| | | exit(EXIT_SUCCESS); |
| | | } |