Hom*_*er6 9 c++ multithreading argument-passing poco-libraries
所以我的问题实际上有几个部分:
使用Poco线程库:
我已经看过这里了:
提前致谢...
Gün*_*nig 17
将参数传递给新线程的规范方法是通过您需要创建的线程入口点的Runnable子类.例:
class MyThread: public Poco::Runnable
{
public:
MyThread(const std::string& arg1, int arg2):
_arg1(arg1),
_arg2(arg2)
{
}
void run()
{
// use _arg1 and _arg2;
//...
}
private:
std::string _arg1;
int _arg2;
};
//...
MyThread myThread("foo", 42);
Poco::Thread thread;
thread.start(myThread);
thread.join();
Run Code Online (Sandbox Code Playgroud)
要将数据传递给已经运行的线程,最佳解决方案取决于您的要求.对于典型的工作线程场景,请考虑使用Poco :: NotificationQueue.可以在此处找到包含解释的完整示例:http://pocoproject.org/slides/090-NotificationsEvents.pdf
| 归档时间: |
|
| 查看次数: |
6219 次 |
| 最近记录: |