Note: This tutorial assumes that you have completed the previous tutorials: Thread.
(!) Please ask about problems and questions regarding this tutorial on Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.


Description: Threading functionality via inheritance.

Keywords: ecl threadable

Tutorial Level: INTERMEDIATE

Next Tutorial: Thread Locks Priorities

The threadable class implements a concept for worker threads that want to retain state information (possibly for use by other parts of the program) in a class. Think of it as a threaded function object rather than a regular c-style threaded function.

Implementation wise, it provides an inheritable interface for your threading class. All the class needs to do is:

  • inherit the Threadable class.

  • implement the runnable() method.

  • call the start() method to begin running in a sepearate thread.

Note that it will not spawn multiple threads - it has a check that ensures it will only execute one thread at any point in time. It is designed to be something more akin to a thread function object rather than a thread factory.

   1 class A : Threadable {
   2     void runnable() {
   3     // thread work here
   4     }
   5 }
   7 int main() {
   8     A a;
   9     a.start();
  10     return 0;
  11 }

Wiki: ecl_threads/Tutorials/Threadable (last edited 2012-01-30 02:59:16 by DanielStonier)