| | |
| | | int key = 2; |
| | | size_t qsize = 16; |
| | | |
| | | // 销毁共享内存和信号 |
| | | void sigint_handler(int sig) { |
| | | destroy(key); |
| | | exit(0); |
| | | |
| | | } |
| | | |
| | | void productor() { |
| | | LockFreeQueue<struct Item> *queue = QueueFactory::createQueue<struct Item> (key, qsize); |
| | | |
| | | // LockFreeQueue<struct Item> *queue = QueueFactory::createQueue<struct Item> (key, qsize); |
| | | SHMQueue<struct Item> *queue = new SHMQueue<struct Item>(key, qsize); |
| | | /* Transfer blocks of data from stdin to shared memory */ |
| | | struct Item item; |
| | | struct timespec timeout = {5, 0}; |
| | |
| | | i++; |
| | | |
| | | } |
| | | delete queue; |
| | | } |
| | | |
| | | |
| | | void consumer() { |
| | | LockFreeQueue<struct Item> *queue = QueueFactory::createQueue<struct Item> (key, qsize); |
| | | SHMQueue<struct Item> *queue = new SHMQueue<struct Item>(key, qsize); |
| | | /* Transfer blocks of data from shared memory to stdout */ |
| | | |
| | | while(1) { |
| | |
| | | } |
| | | |
| | | } |
| | | delete queue; |
| | | } |
| | | |
| | | int main(int argc, char *argv[]) |
| | | { |
| | | |
| | | |
| | | signal(SIGINT, sigint_handler); |
| | | |
| | | |
| | | productor(); |
| | | consumer(); |
| | | |
| | | // 销毁共享内存和信号 |
| | | destroy(key); |
| | | // 销毁共享内存 |
| | | mm_destroy(); |
| | | exit(EXIT_SUCCESS); |
| | | } |