[英]Using the Poco C++ Library, how can I pass data to a thread?
So my question actually has several parts: 所以我的问题实际上有几个部分:
Using the Poco Threading Library: 使用Poco线程库:
I've looked here already: 我已经看过这里了:
Thanks in advance... 提前致谢...
The canonical way of passing arguments to a new thread is via the Runnable subclass you'll need to create as thread entry point. 将参数传递给新线程的规范方法是通过您需要创建的线程入口点的Runnable子类。 Example:
例:
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();
For passing data to an already running thread, what's the best solution depends on your requirements. 要将数据传递给已经运行的线程,最佳解决方案取决于您的要求。 For a typical worker thread scenario, consider using Poco::NotificationQueue .
对于典型的工作线程场景,请考虑使用Poco :: NotificationQueue 。 A complete sample with explanations can be found here: http://pocoproject.org/slides/090-NotificationsEvents.pdf
可以在此处找到包含解释的完整示例: http : //pocoproject.org/slides/090-NotificationsEvents.pdf
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.