So my question actually has several parts:
Using the Poco Threading Library:
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. 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. A complete sample with explanations can be found here: http://pocoproject.org/slides/090-NotificationsEvents.pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With