如何把性病::串入的boost :: lockfree ::队列(或替代)? [英] how to put std::string into boost::lockfree::queue (or alternative)?

查看:407
本文介绍了如何把性病::串入的boost :: lockfree ::队列(或替代)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把的std ::字符串 s转换的boost :: lockfree ::队列太我的线程可以互相用新数据更新。

I'm trying to put std::strings into boost::lockfree::queues so that my threads can update each other with new data.

当我尝试使用的boost :: lockfree ::队列<标准::字符串> updated_data; G ++ 说:

在类boost :: lockfree ::队列>的实例:

In instantiation of 'class boost::lockfree::queue >':

错误:静态断言失败:(的boost :: has_​​trivial_destructor ::值)

error: static assertion failed: (boost::has_trivial_destructor::value)

错误:静态断言失败:(的boost :: has_​​trivial_assign ::值)

error: static assertion failed: (boost::has_trivial_assign::value)

我一直<一个href=\"http://stackoverflow.com/questions/15468278/boost-lockfree-queue-hpp-error-static-assertion-failed-boosthas-trivial-d\">shown一般是什么这些错误意味着,但我没有固定过这个自己的希望,因为我几乎全新的C ++的。

I've been shown generally what these errors mean, but I have no hope of ever fixing this myself, as I'm almost brand new to c++.

是否有其他的方式在线程之间传递文本数据用 lockfree ?如果不是,请告诉我怎么把的std ::字符串的boost :: lockfree ::队列

Is there an alternative way to pass text data between threads with lockfree? If not, please show me how to put std::string into a boost::lockfree::queue.

推荐答案

如果你把原始指针在队列中,旧的的std ::字符串会被泄露,因为有没有办法释放他们不再需要的时候。这是因为没有办法释放一个线程安全的方式对象不以锁(比一些小把戏,比如危险的指针,其中其他的boost :: lockfree ::队列不使用)

If you put raw pointers in the queue, the old std::strings will be leaked, since there is no way to free them when they are no longer needed. This is because there is no way to free the objects in a thread-safe way without taking a lock (other than some tricks like hazard pointers, which boost::lockfree::queue does not use)

由于技术原因,我真的不明白了,的boost :: lockfree ::队列需要一个简单的赋值操作符和析构函数琐碎,这意味着你的对象不能是也不包含必须在其析构函数释放内存的任何数据类型,如的std ::字符串

For technical reasons I do not really understand, the boost::lockfree::queue requires a trivial assignment operator and a trivial destructor, which means that your object cannot be nor contain any data type that must free memory in its destructor, like std::string.

这篇关于如何把性病::串入的boost :: lockfree ::队列(或替代)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆