#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]);
|
}
|
//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];
|
struct timespec timeout = {10, 0};
|
int i = start;
|
// item.pic = i;
|
// item.info = i;
|
//while((end == -1 || (i < end) ) && (queue->add(item)) ) {
|
while(!stop ) {
|
// item.pic = i;
|
// item.info = i;
|
//item = i + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
sprintf(item, "(%d)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", i);
|
if(queue->push_timeout(item, &timeout))
|
cout << "入队:" << item << endl;
|
else
|
break;
|
// cout << item.pic << endl;
|
|
i++;
|
|
}
|
|
delete queue;
|
mm_destroy();
|
cerr << "productor quit" << endl;
|
exit(EXIT_SUCCESS);
|
}
|