PropWare  3.0.0.224
C++ objects and CMake build system for Parallax Propeller
Public Member Functions | Static Public Member Functions | List of all members
PropWare::Runnable Class Referenceabstract

Helper class for creating easy parallel applications. More...

#include <PropWare/concurrent/runnable.h>

+ Inheritance diagram for PropWare::Runnable:

Public Member Functions

virtual void run ()=0
 Invoked in the new cog, this method should be the root of the business logic.
 

Static Public Member Functions

template<class T >
static int8_t invoke (T &runnable)
 Start a new cog running the given object. More...
 

Detailed Description

Helper class for creating easy parallel applications.

To create a Runnable instance which will blink an LED, try the simple example below:

public:
template<size_t N>
BlinkingThread (const uint32_t (&stack)[N], const PropWare::Pin::Mask mask)
: Runnable(stack),
m_mask(mask) {}
void run () {
const PropWare::Pin pin(this->m_mask, PropWare::Pin::OUT);
while (1) {
pin.toggle();
waitcnt(250 * MILLISECOND + CNT);
}
}
private:
const PropWare::Pin::Mask m_mask;
};
int main () {
uint32_t stack[64];
BlinkingThread blinkyThread(stack, PropWare::Pin::P16);
int8_t cog = PropWare::Runnable::invoke(blinkyThread);
pwOut << "Blink thread started in cog " << cog << "\n";
while(1);
}
Examples
DualPWM_Demo.cpp, I2CSlave_Demo.cpp, Runnable_Demo.cpp, SynchronousPrinter_Demo.cpp, UARTRX_Demo.cpp, and WatchDog_Demo.cpp.

Definition at line 75 of file runnable.h.

Member Function Documentation

◆ invoke()

template<class T >
static int8_t PropWare::Runnable::invoke ( T runnable)
static

Start a new cog running the given object.

Parameters
[in]runnableObject that should be invoked in a new cog
Returns
If the cog was successfully started, the new cog ID is returned. Otherwise, -1 is returned

Definition at line 85 of file runnable.h.

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: