作为引用传递的boost线程函数参数(boost::ref()似乎不起作用…)
我有以下简单的功能:作为引用传递的boost线程函数参数(boost::ref()似乎不起作用…),boost,boost-thread,Boost,Boost Thread,我有以下简单的功能: void hda(unsigned long &command) { command++; PlugIn::gResultOut << "inside thread: " << command << std::endl; return; } 输出: before thread: 1 inside thread: 2 after thread: 1 通常使用boost::ref(命令)的答案在这里似乎不起作用
void hda(unsigned long &command)
{
command++;
PlugIn::gResultOut << "inside thread: " << command << std::endl;
return;
}
输出:
before thread: 1
inside thread: 2
after thread: 1
通常使用boost::ref(命令)的答案在这里似乎不起作用。。。。
有什么想法吗?最好不要使用承诺,因为我需要实时观察命令值的变化
谢谢 当您通过
Hthread.join()
内部SU\u Hthread
函数连接线程时会发生什么情况?我将这些函数用作外部软件的包装函数。在线程上使用join总是会冻结软件,即使在这个问题之外……您使用join
等待线程计算的结果,而不使用join
则会打印com
,因为您不知道线程是否结束。我假设您调用sleep(1)
来给线程中的计算留出时间。。
number com = 0
SU_HThread(com)
sleep(1) // sleep 1 second
result("after thread: "+com+" \n")
before thread: 1
inside thread: 2
after thread: 1