The **Active Object** design pattern decouples method execution from method invocation.
An active object is an object that "runs" in a *separate thread*.
It can be useful for in a situation in which an object has to periodically pop elements from a queue, which are in turn produced by a second thread or for example for a receiver object that has to continuously check for incoming messages.
An active object is an object that "runs" in a _separate thread_.
It can be useful for in a situation in which an object has to periodically pop elements from a queue, which are in turn produced by a second thread or for example for a receiver object that has to continuously check for incoming messages.
In `src/shared/` you can find the corresponding template.
## Implementation
The most relevant functions are:
-**virtual bool start()**: creates a Miosix Thread, which in turn call *threadLauncher()*. It returns a bool indicating whether the thread was correctly created or not.
-**virtual bool start()**: creates a Miosix Thread, which in turn call _threadLauncher()_. It returns a bool indicating whether the thread was correctly created or not.
-**virtual void stop()**: stop the ActiveObject's and join its thread.
-**static void threadLauncher(void\* arg)**: private static function that is executed from the thread, which in turn calls the *run()* method.
-**static void threadLauncher(void\* arg)**: private static function that is executed from the thread, which in turn calls the _run()_ method.
-**virtual void run()**: protected method, should be overridden with the code that you want to run in the thread.