我正在开发一个程序,其中 2+ (gstreamer) boost::线程和相同数量的boost::虚拟应用程序的线程同时使用queue。现在这个队列用于gstreamer 线程的任务与其对应的虚拟应用程序线程之间的同步。
该队列是一个 EVENT 队列:其中 EVENT 是一个结构
typedef struct EVENT{
EVENT_TYPE Ev_Type; // EVENT_TYPE is enum of Events
EVENT_DATA Ev_Data; // EVENT_DATA is union of data to be stored for that event
}Event_;
谷歌搜索后,我发现了队列的这两个选项:lockfree::queue和lockfree::spsc_queue,这表明lockfree::queues
它们用于多线程应用程序。
困惑:为什么叫 lockFREE?是否暗示不能(互斥)锁定?
另见这个例子,它说“boost::lockfree::queue is not lockfree”
头脑=吹...
好吧,然后我尝试按照示例(以上链接)并实现此队列
class Foo {
protected:
boost::lockfree::queue<EVENT> mqSttEventQueue;
public:
unsigned int SetEventIntoQueue(EVENT *psEvent);
};
其定义为:
unsigned int Foo::SetEventIntoQueue(EVENT *psEvent) {
if(mqSttEventQueue.push(*psEvent)){
//notify that event is in queue;
}
}
这样就编译成功了。但我在这里完全是在黑暗中奔跑。
问题:
为什么该示例将队列声明为
boost::lockfree::queue<int> queue(128);
那128是干什么用的?是说队列大小是 128(字节/项)吗?是否queue<int>
声明队列中的数据类型?
为什么它对我的程序不起作用
boost::lockfree::queue<EVENT> mqSttEventQueue(128);
如果我这样声明它,它会得到编译错误
error: expected identifier before numeric constant boost::lockfree::queue<EVENT> mqSttEventQueue(128); ^~~
PS:-我真的不确定在这里放什么标题...如果可以的话,请编辑它。