#include "test.h"
|
|
using namespace std;
|
|
SQueue<struct Item> *queue;
|
|
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 */
|
|
/*mm_init(sizeof(deque<string, myallocator::Allocator<string> >), &shmp);*/
|
/*deque<string, myallocator::Allocator<string> > *queue = (deque<string, myallocator::Allocator<string> > *) shmp;*/
|
|
|
|
int first = mm_init(sizeof(SQueue<struct Item>), &shmp);
|
|
if (first == 1)
|
queue = new(shmp) SQueue<struct Item>;
|
else
|
queue = (SQueue<struct Item> *) shmp;
|
/* Transfer blocks of data from shared memory to stdout */
|
|
while(1) {
|
struct Item item;
|
if (queue->dequeue_nowait(item)) {
|
cout << "出队:" << item.pic << ", " << item.info << endl;
|
} else {
|
cout << "队列为空,dequeue_nowait返回" << endl;
|
}
|
|
struct timespec timeout = {5, 0};
|
|
if (queue->dequeue_timeout(item, &timeout)) {
|
cout << "出队:" << item.pic << ", " << item.info << endl;
|
} else {
|
cout << "队列为空,等待5 s,dequeue_timeout返回" << endl;
|
}
|
|
sleep(1);
|
}
|
|
|
destroy();
|
exit(EXIT_SUCCESS);
|
}
|