wangzhengquan
2020-07-08 7d3086a481899b03c230eb06a29aa57677041725
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "test.h"
using namespace std;
 
 
int key = 1;
bool stop = false;
void sigint_handler(int sig) {
  
  stop = true;
 
}
 
int main(int argc, char *argv[])
{
   
  int qsize = 16;
 
  signal(SIGINT,  sigint_handler);
 
  // SHMQueue<struct Item, 3> *queue = new SHMQueue<struct Item, 3>(qsize);
  SHMQueue<struct Item> *queue = new SHMQueue<struct Item>(key, qsize);
  
  //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(!stop && queue->pop(item)) {
    cout << "出队:" << item.pic << ", " << item.info << endl;
    //cout <<  item.pic  << endl;
    //sleep(1);
  }
 
  delete queue;
  mm_destroy();
  cerr << "consumer quit" << endl;
  exit(EXIT_SUCCESS);
}