草庐IT

thread_siblings_list

全部标签

c++ - Thread Sanitizer 是否可用?

我想尝试线程清洁剂(http://code.google.com/p/data-race-test/wiki/ThreadSanitizer#Using_ThreadSanitizer)所以我做了一个简单的程序:#include#include#include#include#include#includeusingnamespacestd;intviolated=0;mutexmtx;voidviolator(){lock_guardlg(mtx);violated++;}intmain(){threadt1(violator);t1.join();threadt2(violator

c++ - 使用 std::list 提高简单性

有哪些更好(更清洁、更易读和/或更有效)的方法:std::listApples;std::listBasket;for(std::list::iteratorniApple(Apples.begin());niApple!=Apples.end();niApple++){for(std::list::iteratorniBasket(Basket.begin());niBasket!=Basket.end();niBasket++){if(&(*niBasket)==*niApple){Basket.erase(niBasket);break;}}//loop}//loop你会推荐什么

c++ - malloc 和堆 : extra memory for storing the size and linked list information?

我有一个关于heap和malloc的简单问题:当我们使用malloc分配一些内存空间时,如下所示:int*p;p=(int*)malloc(10*sizeof(int));它实际上在堆中分配了10个单词。但是,我的问题是:实际使用的内存空间真的是10个字?或者还有其他额外的空间需要存储内存大小的值?或者,甚至,因为堆的结构是链表,是否有其他内存空间用于存储指向堆中列表的下一个节点的地址? 最佳答案 它完全依赖于实现。a)它可以在每个分配的节点之前有几个字节,其中包含节点的大小、指向下一个节点的指针,可能还有前一个节点指针和节点类型。

c++ - 如何删除 STD::List 中最近的 "Point"对象到某个 x,y?

我有一个点类:classPoint{public:intx,y;Point(intx1,inty1){x=x1;y=y1;}};和点列表:std::listpointList;std::list::iteratoriter;我正在将点推送到我的pointList(尽管如果尚未推送任何点,该列表可能还不包含任何点)。我有两个问题:如何从列表中删除最接近任意点(x,y)的点?假设我有x,y(5,12),我想在列表中找到最接近该点的点并将其从STD::List中删除。我知道我必须使用距离公式并且我必须使用迭代器遍历列表但是我在概念化如何在我迭代时跟踪哪个点最近时遇到了一些问题通过列表。如何返

c++ - 从 std::thread 调用 boost::asio::io_service::run

我有一个处理我的连接的类,它有一个boost::asio::io_service成员。我想从std::thread调用io_service::run(),但我遇到了编译错误。std::threadrun_thread(&boost::asio::io_service,std::ref(m_io_service));不起作用。我看到了使用boost::thread执行此操作的各种示例,但我想为此坚持使用std::thread。有什么建议么?谢谢 最佳答案 我知道有两种方法,一种是通过lambda创建std::thread。std::t

c++ - 避免 std::list 中的指针

我尽量避免有指针,而不是做std::list*>myList;voidaddElement(inta,intb){myList.push_back(newstd::pair(a,b));}我想我可以做类似的事情std::list>myList;voidaddElement(inta,intb){std::pairp(a,b);myList.push_back(p);}如果我对行为的理解正确,这应该存储对的拷贝,并在执行myList.clear()时自动删除它(与指针相反)。这是最好的方法吗?我可以期望编译器优化掉不必要的对象p吗? 最佳答案

c++ - std::list<>:l.begin() 之前的元素

简短的问题:使用与我不同的其他编译器(mingw32),以下代码是否不安全,或者是否可以使用?listl;/*addelements*/list::iteratori=l.begin();i--;i++;cout...或者换句话说:i是否定义为指向此之后的l.begin()? 最佳答案 是的,代码是不安全的。一旦您尝试在begin()之前移动,您就会导致未定义的行为。尝试“再次返回”可能行不通。 关于c++-std::list:l.begin()之前的元素,我们在StackOverflo

c++ - 加速 C++ : Can I write a program that sorts either a list or a vector using the same command?

我意识到std::sort函数需要使用随机访问迭代器,而列表具有双向迭代器。有一个关于此的问题:SortlistusingSTLsortfunction我正在努力回答AcceleratedC++书中的问题5-4以供家庭学习。5-4.Lookagainatthedriverfunctionsyouwroteinthepreviousexercise.Notethatitispossibletowriteadriverthatonlydiffersinthedeclarationofthetypeforthedatastructurethatholdstheinputfile.Ifyour

c++ - 使用 shared_ptr 启动 std::thread

当你构造一个新线程时,提供的函数对象被复制到属于新创建线程的存储中。我想在一个新线程中执行一个对象方法。不应复制该对象。所以我将对象的shared_ptr传递给std::thread构造函数。如何使用std::shared_ptr()对象启动新线程?例如classFoo{public:voidoperator()(){//dosomething}};intmain(){std::shared_ptrfoo_ptr(newFoo);//Iwanttolaunchafoo_ptr()inanewthread//Isthisthecorrectway?std::threadmyThread(

c++ - 为什么是 std::this_thread 命名空间?

按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。std::this_thread命名空间是否有技术原因?为什么这个命名空间的成员不能作为std::thread类的静态成员实现?