wangzhengquan
2020-07-20 f75a37444e7a97fb58439077eea4d1b3c576bfe3
test/single_productor.c
@@ -2,21 +2,21 @@
 
using namespace std;
int key = 1;
bool stop = false;
void sigint_handler(int sig) {
  cerr << "sigint_handler" << endl;
  destroy(key);
  exit(0);
  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. */
@@ -27,29 +27,41 @@
    start = atoi(argv[1]);
    end = atoi(argv[2]);
  }
  //SAbstractQueue<struct Item> *queue = QFactory::createQueue<struct Item> (1, 10);
  LockFreeQueue<struct Item> *queue = QueueFactory::createQueue<struct Item> (key, qsize);
  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 */
  struct Item item;
  struct timespec timeout = {5, 0};
  //item_t item;
  //char item[1024];
  item_t item;
  struct timespec timeout = {10, 0};
  int i = start;
  item.pic = i;
  item.info = i;
  //while((end == -1 || (i < end) ) && (queue->add(item)) ) {
  while((queue->push(item)) ) {
    item.pic = i;
    item.info = i;
    // cout << "入队:" << item.pic << ", " << item.info << endl;
    cout <<  item.pic << endl;
  // 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++;
    
  }
  destroy(key);
  cerr << "productor quit" << endl;
  //delete queue;
  //mm_destroy();
  err_msg(0, "productor quit");
  exit(EXIT_SUCCESS);
}