草庐IT

thread_func

全部标签

c - 解释 void (*signal(int signo, void *(func)(int)))(int)

请解释此类型签名:void(*signal(intsigno,void*(func)(int)))(int) 最佳答案 当typedef用于传递的函数指针时,signal函数的类型签名更加清晰:typedefvoid(*sighandler_t)(int);sighandler_tsignal(intsigno,sighandler_tfunc);sighandler_t是一个指向函数的指针,该函数采用int参数并且不返回任何内容。signal函数将这样一个函数指针作为它的第二个参数。它还返回该类型的函数指针。

c++ - 如果在 linux Ubuntu :)10. 10 中包含 boost/thread,则不会编译

我在linuxUBUNTU下的eclipse中工作:)10.10,使用Synapticpkg管理器安装了boost-dev包1.40。我是linux的新手,这个boostpkg。我尝试创建一个新项目,并写下:#includeintmain(intargc,char*argv[]){}我没有在任何地方包含任何东西或编写任何类似pthread的东西。尝试构建时,它说:/usr/include/boost/config/requires_threads.hpp:47:error:#error"Compilerthreadingsupportisnotturnedon.Pleasesetthe

c++ - 访问静态初始化的 __thread 变量时出现段错误

考虑以下代码:#include__threadboolfoo=true;intmain(){printf("foo=%d\n",foo);return0;}编译并运行:$g++tls.cpp-otls-otls$./tls在某些系统上——例如AmazonLinux2013.09.0、ami-5b792c32、内核3.4.62-53.42.amzn1.i686、g++4.6.320120306(RedHat4.6.3-2)——这会导致一旦访问foo就会出现段错误。另一方面,在代码中显式初始化foo不会导致段错误:#include__threadboolfoo=true;intmain()

linux - "Compiler threading support is not turned on."

通常我可以通过谷歌搜索找到解决方案,但这次不行。我正在使用64位LinuxUbuntu11.04编译32位Windows应用程序。我正在使用i586-mingw32msvc-gcc来编译我的C++文件。测试.cpp:#include生成文件:i586-mingw32msvc-gcc-c-m32-mthreads-otest.otest.cpp错误:boost/asio/detail/socket_types.hpp:#includedoesn'texist.添加到makefile:-DBOOST_WINDOWSError:#warningPleasedefine_WIN32_WINNT

C++ boost::thread,如何在类中启动线程

如何在一个对象中启动一个线程?例如,classABC{public:voidStart();doublex;boost::threadm_thread;};ABCabc;...dosomethinghere......howcanIstartthethreadwithStart()function?,......e.g.,abc.m_thread=boost::thread(&abc.Start());...这样以后我就可以做类似的事情abc.thread.interrupt();abc.thread.join();谢谢。 最佳答案

c++ - 错误 : ‘struct sigevent’ has no member named ‘sigev_notify_thread_id’

以下“玩具”代码表示我在使用POSIXtimers的较大代码库中遇到的问题.#include#include#include#includeusingnamespacestd;intmain(){structsigeventsevp;longthreadId=5;sevp.sigev_notify=SIGEV_THREAD_ID;sevp.sigev_notify_thread_id=threadId;return0;}当我尝试在Linux机器上使用g++编译它时,出现错误:error:‘structsigevent’hasnomembernamed‘sigev_notify_thre

linux - 为什么使用 std::thread::hardware_concurrency() 和 boost::thread::hardware_concurrency() 有区别?

问题本身的描述很简单。我正在测试C++11中std::thread库和boost::thread库的区别。这些的输出:#include#include#includeintmain(){std::cout给我不同的结果:04这是为什么?PS:gcc包的版本是4.6.2-1.fc16(x86_64)。我正在使用g++test.cc-Wall-std=c++0x-lboost_thread-mt-lpthread 最佳答案 查看/usr/include/c++/4.6.2/thread后可以看出实现其实是://Returnsavalue

php - 在 PHP 中获取唯一的 worker/thread/process/request ID

在多线程环境(如大多数网络平台)中,我经常在我的应用程序日志中包含某种线程ID。当同时有多个请求同时写入同一个日志时,这使我能够准确判断哪个日志条目来自哪个请求/线程。在.NET/C#中,这可以通过log4net的格式化程序完成,默认情况下包括当前线程的ManagedThreadId(一个数字)或Name(一个给定的姓名)。这些属性唯一标识一个线程(参见示例:HowtologcorrectcontextwithThreadpoolthreadsusinglog4net?在PHP中,我没有发现任何类似的东西(我问过Google、PHP文档和SO)。存在吗? 最

PHP pthreads : Fatal error: Class 'Thread' not found

我在我的网络服务器上使用php5.5。现在我想使用pthreads。这是我的php配置:http://dd19010.kasserver.com/infophp.php55执行此代码后......threadId=$threadId;}publicfunctionrun(){printf("T%s:Sleeping3sec\n",$this->threadId);sleep(3);printf("T%s:HelloWorld\n",$this->threadId);}}$start=microtime(true);for($i=1;$istart();}echomicrotime(tr

php - call_user_func() 期望参数 1 是一个有效的回调

我只是在PHP中使用call_user_func函数,在运行这个简单的代码时遇到了这个错误:var=$string;}publicfunctionfoo(){call_user_func($this->var);}}$a=newA('printHi');$a->foo();?>我知道如果我在名为printHi的类之外创建一个函数,它工作正常,但我指的是该类的printhi并且不确定为什么没有注册“this”。 最佳答案 $this->var在您的示例中评估为printHi。但是,当调用类的方法时,需要将回调作为数组传递,其中第一个元