参数传递给函数在一个boost ::线程 [英] pass arguments to function in a boost::thread
问题描述
这是使用升压线程函数,并在此之前,我有一个多线程的工作知之甚少我的第一次。我试图同时运行初始调用一个函数的第二个实例,这样就可以通过两个不同的变量相同的功能,我希望我的速度向上的程序。与code我知道,我不断收到一个错误C2784它说
'T *的boost :: get_pointer(常量的boost :: scoped_ptr的< T>&安培;):不能推导出模板参数的常量的boost :: scoped_ptr的< T> &放大器;'从'常量的std ::字符串'
这里的code的,与线程创建交易的段
字符串firstPart = recText.substr(1,(subPart1-1));
串二部= recText.substr(subPart1,subPart1);提高::螺纹firstThread;
提高::螺纹secondThread;firstThread =的boost ::线程(安培;转换::转换,firstPart);
secondThread =的boost ::线程(安培;转换::转换,二部);
firstThread.join();
secondThread.join();
修改
无效转换::转换(字符串_Part)
{
INT value_Part = 1;
INT valueShort = 0;
int值=校验值;
如果(价值== value_Part)
{
// 做东西
}
}
成员函数取类型的隐式的第一个参数(CV合格) T *
,其中 T
与成员函数的类。您需要将指针传递给一个转换
实例,例如,
转成c;
firstThread =的boost ::线程(安培;转换::转换,和C,firstPart);
This is my first time using the boost thread function and prior to this I have little knowledge of working with multiple threads. I attempting to run a second instance of a function alongside the initial call so I can pass two different variables to the same function, which I'm hoping speeds my program up. with the code I have know I keep getting a C2784 Error which says
'T *boost::get_pointer(const boost::scoped_ptr<T> &)' : could not deduce template argument for 'const boost::scoped_ptr<T> &' from 'const std::string'
here's the snippet of code that deals with the thread creation
string firstPart = recText.substr(1,(subPart1-1));
string secondPart = recText.substr(subPart1,subPart1);
boost::thread firstThread;
boost::thread secondThread;
firstThread = boost::thread(&Conversion::conversion,firstPart);
secondThread = boost::thread(&Conversion::conversion,secondPart);
firstThread.join();
secondThread.join();
edit
void Conversion::conversion(string _Part)
{
int value_Part = 1;
int valueShort = 0;
int value = checkValue;
if(value == value_Part)
{
// do stuff
}
}
Member functions take an implicit first parameter of type (cv qualified) T*
, where T
is the class with the member function. You need to pass a pointer to a Conversion
instance, for example,
Conversion c;
firstThread = boost::thread(&Conversion::conversion, &c, firstPart);
这篇关于参数传递给函数在一个boost ::线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!