wangzhengquan
2020-07-07 082633f08aae8eea19bd7050cbe4a75e5ed1ac6f
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
#include "test.h"
using namespace std;
 
 
 
 
void sigint_handler(int sig) {
  destroy();
  exit(0);
 
}
int main(int argc, char *argv[])
{
   
 
  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);
  /* Transfer blocks of data from shared memory to stdout */
   
  struct timespec timeout = {10, 0};
  struct Item item;
  while(queue->remove(item)) {
    
    cout <<  item.pic  << endl;
    //sleep(1);
  }
 
  destroy();
  cerr << "consumer quit" << endl;
  exit(EXIT_SUCCESS);
}