wangzhengquan
2020-07-27 d94bfb19c54d4b980c1b4d63b42f3dfa0bc202a6
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "test.h"
 
 
using namespace std;
int key = 1;
bool stop = false;
void sigint_handler(int sig) {
  printf("sigint_handler\n");
  stop = true;
}
 
int main(int argc, char *argv[])
{
 
 
  string line;
  signal(SIGINT,  sigint_handler);
  int qsize = 16;
 
 
  /* Create set containing two semaphores; initialize so that
     writer has first access to shared memory. */
  int start = 0;
  int end = -1; 
 
  if (argc == 3) {
    start = atoi(argv[1]);
    end = atoi(argv[2]);
  }
 
  mm_init(512);
  //LockFreeQueue<item_t> *queue = QueueFactory::createQueue<item_t> (key, qsize);
  SHMQueue<item_t> *queue = new SHMQueue<item_t>(key, qsize);
  
 
  /* Transfer blocks of data from stdin to shared memory */
  //item_t item;
  //char item[1024];
  item_t item;
  struct timespec timeout = {10, 0};
  int i = start;
  // item.pic = i;
  // item.info = i;
  while(!stop && (end == -1 || (i < end) ) ) {
  //while(!stop ) {
    // item.pic = i;
    // item.info = i;
    //item = i + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    //sprintf(item, "(%d)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", i);
    if(queue->push(i))
      //cout << "入队:" << item << endl;
       LoggerFactory::getLogger().error("%d", i);
      // err_msg(0, "%d", i);
    else {
      break;
    }
   // cout <<  item.pic << endl;
 
    i++;
    
  }
 
  //delete queue;
  //mm_destroy();
  err_msg(0, "productor quit");
  exit(EXIT_SUCCESS);
}