草庐IT

thread_name

全部标签

c++ - 使用 std::shared_ptr 对象实例创建 boost::thread

我有以下两个代码段。第一个block按预期编译和工作。但是第二个block不编译。我的问题是,给定下面的代码,当尝试基于由shared_ptr代理的对象实例创建线程时,正确的语法是什么?#include#include#include#includestructfoo{voidboo(){}};intmain(){//Thisworks{foo*fptr=newfoo;boost::threadt(&foo::boo,fptr);t.join();deletefptr;}//Thisdoesn'twork{std::shared_ptrfptr(newfoo);boost::threa

c++ - 枚举 "does not name a type' 的问题

g++(Ubuntu/Linaro4.4.4-14ubuntu5)4.4.5我有一个问题,我似乎找到了我得到这个错误的方法。文件statemachine.h#ifndefSTATEMACHINE_H_INCLUDED#defineSTATEMACHINE_H_INCLUDED#include"port.h"enumstate{ST_UNINITIALIZED=0x01,ST_INITIALIZED=0x02,ST_OPENED=0x03,ST_UNBLOCKED=0x04,ST_DISPOSED=0x05};voidstate_machine(eventevt,port_t*port)

c++ - std::thread Visual Studio 2012 警告

我试图了解如何通过VisualStudio2012使用新的std::thread。我正在尝试编译以下代码。#include#includeclassscoped_thread{std::threadt_;public:explicitscoped_thread(std::thread&t):t_(std::move(t)){if(!t_.joinable())throwstd::logic_error("Nothread");}~scoped_thread(){t_.join();}private:scoped_thread(scoped_threadconst&);scoped_th

c++ - 链接到 boost_thread 的问题

我正在尝试将xubuntu上的boost1.47与gcc4.6和glibc2.13链接起来。到目前为止,我无法编译以下简单程序main.cpp:#include#include#includeintmain(){size_tn_threads=boost::thread::hardware_concurrency();return0;}当我编译时:g++-lboost_thread-lboost_regex-omcmain.cpp-static-lpthread/usr/local/lib/libboost_regex.a/usr/local/lib/libboost_thread.a

c++ - 错误 : ‘i’ does not name a type with auto

这个问题在这里已经有了答案:HowdoIenableC++11ingcc?(4个答案)关闭7年前。我是C++新手,这是我的程序#include#include#include#include#includeintmain(){staticconstdoublearr[]={16.0,2.2,77.5,29.0,24.0};std::vectorvec(arr,arr+sizeof(arr)/sizeof(arr[0]));std::transform(vec.begin(),vec.end(),vec.begin(),bind2nd(std::minus(),3.0));for(aut

c++ - 指向 std::thread 的共享指针是一种不好的做法吗?

使用std::shared_ptr有意义吗?逻辑很简单:如果不需要线程,则删除它,如果需要新线程-重新分配它。有什么方法可以将这个概念与线程池进行比较吗?我确实知道我系统中线程的确切数量(我开发了图像处理算法,我想给“算法”类的每个子级一个单独的线程(也许让它私有(private),然后不需要shared_ptr),该算法将在何处运行,如果未提供图像,则将此私有(private)线程闲置。这是一个糟糕的概念吗? 最佳答案 您可能错过了事实std::thread析构函数不会终止线程。正如评论中已经提到的,ifdetachorjoinw

c++ - std::this_thread::sleep_for(2s) 中的 s 是什么?

我找到了std::this_thread::sleep_for可以处理时间单位s。std::this_thread::sleep_for(2s);但是我不知道2s中的s是什么。 最佳答案 Whatissinstd::this_thread::sleep_for(2s)?s是一个用户定义的文字使得2schrono::second类型的文字值.内置文字您可能熟悉integerliterals和floatingliterals;这些是内置后缀:+--------+---------+---------------+|Suffix|Exam

c++ - 错误 : '...' does not name a type

我有一个工作项目。重新安排一些代码后,我尝试重新编译我的项目,然后奇怪的事情开始发生。查看编译器输出的这段摘录。我正在使用MinGWG++从Windows上的Eclipse进行编译。****BuildofconfigurationDebugforprojectPract2********InternalBuilderisusedforbuild****g++-O0-g3-Wall-c-fmessage-length=0-omove.o..\move.cppInfileincludedfrom..\/game.h:11:0,from..\/piece.h:10,from..\/move.

c++ - 继承 : expected class-name before ‘{’ token

我试图在C++中创建一个异常类,但它不起作用。我已将代码减少到最少,但仍然找不到错误。这是我的头文件:#ifndefLISTEXCEPTION_H#defineLISTEXCEPTION_H//C++standardlibraries#include/*CLASSDEFINITION*/classListException:publicexception{};#endif//LISTEXCEPTION_H这是我得到的错误:error:expectedclass-namebefore‘{’token这是出乎意料的。我该如何解决这个问题? 最佳答案

c++ - (C++ 线程): Creating worker threads that will be listening to jobs and executing them concurrently when wanted

假设我们有两个worker。每个worker都有一个0和1的id。还假设我们一直有工作到达,每个工作也有一个标识符0或1指定哪个worker必须做这个工作。我想创建2个线程,它们最初是锁定的,然后当两个作业到达时,解锁它们,每个线程都完成它们的工作,然后再次锁定它们,直到其他作业到达。我有以下代码:#include#include#includeusingnamespacestd;structjob{threadjobThread;mutexjobMutex;};jobjobs[2];voidexecuteJob(intworker){while(true){jobs[worker].