ACE消息队列 ACE_Message_Queue 入队列,出队列方法(1)

本文介绍了如何使用ACE库中的ACE_Message_Queue模板类进行消息队列的操作,包括对象入队和出队的示例。示例中展示了将student对象存入队列并在出队时读取,确保了线程安全。通过实例代码详细解释了入队和出队的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ACE提供的的消息队列 ACE_Message_Queue,作为一个容器类,  不仅可以在其中存储一个具体的对象,也可以存储一个对象的指针。使用起来十分的方便。另外它是一个模板类,在定义的时候可以选择多线程同步工作模式,所以它也可以在线程安全的模式下工作。下边的代码是测试存储对象类为一个stduent类。
// lesson_queue.cpp : Defines the entry point for the console application.


#include "ace/Message_Queue.h"
#include "ace/Synch.h"
#include "string"
#include "iostream"

using namespace std;

class student
{
public:
	student(){}
	~student(){}
	int    number;
	char   name[10];
	int    english;
	void output(int i)
	{
		if (i == 1)
		{
			cout<<"insert " << "number=" << number << " name=" << name << " english=" << english <<endl; 
		}
		else
		{
			cout<<"delete " << "number=" << number << " name=" << name << " english=" << english <<endl; 
		}
	}
};


int main(int argc, char* argv[])
{
	ACE_Message_Queue
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值