This tutorial will guide you to understand and develop a multi-thread module using YARP threads API. After doing this tutorial you will be expected to know how to write a proper multi-thread module, using semaphore and etc.
will guide you to the use
In this tutorial we will develop a YARP module called tutorial_yarp-multithreading
to produce a painted image in YARP and send it via YARP port. We will use multiple thread to take advantage of multi core CPUs for faster data processing.
Follow these steps to build and properly install your module:
$ cd tutorial_yarp-multithreading
$ mkdir build; cd build
$ cmake ../
$ make
$ make install
the make install
will install your module (binary, xml files, etc) in the icub Contrib folder which is already setup on your machine.
- Simply run the
yarpmanager
and open/run theTutorial_yarp-multithreading
application for the GUI then connect the ports:
$ yarpmanager
you should be able to see the following output on the yarpview
:
While the module is running, right click on the tutorial_yarp-multithreading
and attach to stdout to see the messages printed by the module. Alternatively you can run the yarplogger
and monitors the printed messages there. The module continuously print the total processing time to create (paint) the image.
$ tutorial_yarp-multithreading --threads 1 --width 320 --height 240
[INFO]Processing time 37.38 ms
[INFO]Processing time 37.303 ms
...
Running tutorial_yarp-multithreading
with two threads
Stop the module, double click on the parameters and change the --threads
parameter to --threads 2
. Or simply run it from the terminal:
$ tutorial_yarp-multithreading --threads 2 --width 320 --height 240
[INFO]Processing time 16.5989 ms
[INFO]Processing time 16.8562 ms
...
Running tutorial_yarp-multithreading
with four threads
Stop the module, double click on the parameters and change the --threads
parameter to --threads 4
. Or simply run it from the terminal:
$ tutorial_yarp-multithreading --threads 4 --width 320 --height 240
[INFO]Processing time 10.601 ms
[INFO]Processing time 10.617 ms
...
this module needs to use semaphores to regulate the access of the different threads to the RF module