Passing messages both ways between a class and a worker thread

Please post support and help requests here.
dtalmage
Posts: 2
Joined: 21 Jun 2017, 12:56

Passing messages both ways between a class and a worker thread

Postby dtalmage » 21 Jun 2017, 13:00

What is the recommended way to pass messages both ways between a class and its worker thread, using C++11 & Poco?

I have a class that uses a thread to do some of its work (in particular, so that the thread can read frames from a video file and store them). I am using Poco to create the thread (using Poco::Thread) and the thread handler (using Poco::Runnable). I'm then passing messages by using Poco::Notification from the class to the worker thread. This works fine to send messages one-way from the class to the worker thread.

I also want to send messages back the other way (for example, for the worker thread to tell the parent class that the video can't be opened or that all the frames have been read). Is there a recommended way to do this using the Poco library, and, if so, what it is?

The Poco documentation describes using both Notifications and Events to pass messages. It may be that the right way is to set up two NotificationQueues (one for each direction), or that the best way is for the parent class to send messages to the thread using a NotificationQueue and for the worker thread to send messages back using Poco::Event

Many thanks for any help you can give.

guenter
Posts: 1268
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Passing messages both ways between a class and a worker thread

Postby guenter » 24 Jun 2017, 13:33

I'd recommend to use two NotificationQueues. One to pass work items to worker thread(s), and another one to pass notifications back from worker threads to the main thread. As outlined in these slides.


Return to “Support”

Who is online

Users browsing this forum: No registered users and 3 guests

cron