草庐IT

scoped_thread

全部标签

c++ - std::this_thread::sleep_for() 和 GCC

当我尝试编译这个简单的程序时:#includevoidf(){std::this_thread::sleep_for(std::chrono::seconds(3));}intmain(){std::threadt(f);t.join();}在Ubuntu10.04(32位)上使用gcc版本4.4.3:$g++-std=c++0x-pthreada.cpp-oa我明白了:error:‘sleep_for’isnotamemberof‘std::this_thread’我查看了标题“线程”。sleep_for()受_GLIBCXX_USE_NANOSLEEP保护#ifdef_GLIBCX

c++ - 在 C++11 中通过引用 std::thread 传递对象

为什么在创建std::thread时不能通过引用传递对象?例如,以下代码段给出了编译错误:#include#includeusingnamespacestd;staticvoidSimpleThread(int&a)//compileerror//staticvoidSimpleThread(inta)//OK{cout错误:Infileincludedfrom/usr/include/c++/4.8/thread:39:0,from./std_thread_refs.cpp:5:/usr/include/c++/4.8/functional:Ininstantiationof‘str

c++ - 在 C++11 中, "does not represent a thread of execution"的线程有什么意义?

查看C++11中的新线程以了解它映射到pthread的难易程度,我注意到thread构造函数区域中的奇怪部分:thread();Effects:Constructsathreadobjectthatdoesnotrepresentathreadofexecution.Postcondition:get_id()==id()Throws:Nothing.换句话说,线程的默认构造函数实际上似乎并没有创建线程。显然,它创建了一个线程对象,,但是如果没有支持代码,它到底有什么用呢?是否有其他方式可以将“执行线程”附加到该对象,例如thrd.start()或类似的东西?

c++ - 在 C++11 中设置 std::thread 优先级的可移植方法

在后C++11世界中,设置std::thread实例优先级的正确方法是什么是否有至少在Windows和POSIX(Linux)环境中有效的可移植方式?或者是获取句柄并使用特定操作系统可用的任何native调用的问题? 最佳答案 无法通过C++11库设置线程优先级。我认为这在C++14中不会改变,而且我的Crystal球太模糊了,无法评论之后的版本。在POSIX中,pthread_setschedparam(thread.native_handle(),policy,{priority});在Win32BOOLSetThreadPri

c++ - 为什么这个简单的 std::thread 示例不起作用?

尝试使用g++-std=gnu++0xt1.cpp和g++-std=c++0xt1.cpp编译以下示例,但这两者导致示例中止。$./a.outterminatecalledafterthrowinganinstanceof'std::system_error'what():Aborted示例如下:#include#includevoiddoSomeWork(void){std::cout我正在Ubuntu11.04上尝试这个:$g++--versiong++(Ubuntu/Linaro4.5.2-8ubuntu4)4.5.2有人知道我错过了什么吗? 最佳答案

c++ - QObject : Cannot create children for a parent that is in a different thread

我在Windows7Ultimate下使用Qt4.6.0(32位)。考虑以下QThread:界面classResultThread:publicQThread{Q_OBJECTQString_post_data;QNetworkAccessManager_net_acc_mgr;signals:voidonFinished(QNetworkReply*net_reply);privateslots:voidonReplyFinished(QNetworkReply*net_reply);public:ResultThread();voidrun();voidsetPostData(co

Eclipse IDE 中的 C++ 错误 'nullptr was not declared in this scope'

我正在运行EclipseHelios,并且安装了g++-4.6。希望g++4.6实现C++11特性我没有错。我创建了一个使用nullptr和auto关键字的C++项目。该构建给出以下错误:-../{filename}.cpp:13:13:error:‘nullptr’wasnotdeclaredinthisscope../{filename}.cpp:14:2:warning:‘auto’willchangemeaninginC++0x;pleaseremoveit[-Wc++0x-compat]实际上,直到昨天它还在build中。我今天不知从何而来。请帮我解决这个问题。

c++ - boost::scoped_ptr<T> 和 std::unique_ptr<T> 之间的区别

是boost::scoped_ptr之间的唯一区别和std::unique_ptr事实std::unique_ptr具有移动语义,而boost::scoped_ptr只是一个get/reset智能指针? 最佳答案 不,但这是最重要的区别。另一个主要区别是unique_ptr可以有一个析构函数对象,类似于shared_ptr能够。不像shared_ptr,析构函数类型是unique_ptr的一部分的类型(分配器是STL容器类型的一部分)。一个constunique_ptr可以有效地完成scoped_ptr的大部分工作可以做;确实,不像

c++ - 类的std::thread调用方法

这个问题在这里已经有了答案:关闭10年前.PossibleDuplicate:Startthreadwithmemberfunction我有一个小类:classTest{public:voidrunMultiThread();private:intcalculate(intfrom,intto);}如何使用两组不同的参数运行方法calculate(例如calculate(0,10),calculate(11,20))在两个线程中来自方法runMultiThread()?PS谢谢我忘了我需要传递this作为参数。 最佳答案 没那么难:

javascript - Angular JS : What is the need of the directive’s link function when we already had directive’s controller with scope?

我需要对范围和模板执行一些操作。看来我可以在link函数或controller函数中做到这一点(因为两者都可以访问范围)。什么时候我必须使用link函数而不是Controller?angular.module('myApp').directive('abc',function($timeout){return{restrict:'EA',replace:true,transclude:true,scope:true,link:function(scope,elem,attr){/*linkfunction*/},controller:function($scope,$element){