如何把性病::串入的boost :: lockfree ::队列(或替代)? [英] how to put std::string into boost::lockfree::queue (or alternative)?
问题描述
我试图把的std ::字符串
s转换的boost :: lockfree ::队列
太我的线程可以互相用新数据更新。
I'm trying to put std::string
s into boost::lockfree::queue
s 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屋!