wangzhengquan
2020-07-08 3710ce88088c00599c5b108456f6dde9a4d981bc
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<item_t> *queue = new SHMQueue<item_t>(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};
  item_t item;
  while(!stop && queue->pop_timeout(item, &timeout)) {
    cout << "出队:" << item << endl;
    //cout <<  item.pic  << endl;
    //sleep(1);
  }
 
  delete queue;
  mm_destroy();
  cerr << "consumer quit" << endl;
  exit(EXIT_SUCCESS);
}