modm API documentation
modm::pt::Protothread Class Reference

A very lightweight, stackless thread. More...

#include <modm/processing/protothread/protothread.hpp>

Inheritance diagram for modm::pt::Protothread:
modm::ds1631< I2cMaster > modm::Tmp102< I2cMaster > modm::Tmp175< I2cMaster > TestingChildThread TestingEmptyThread TestingThread TestingThreadRestart

Public Member Functions

 Protothread ()
 Construct a new protothread that will start from the beginning of its run() function.
 
void restart ()
 Restart protothread.
 
void stop ()
 Stop the protothread from running. More...
 
bool isRunning () const
 Check if the protothread is still running. More...
 

Detailed Description

A very lightweight, stackless thread.

Because protothreads do not save the stack context across a blocking call, local variables are not preserved when the protothread blocks. This means that local variables should be used with utmost care - if in doubt, do not use local variables inside a protothread! Use private/protected member variables to save state between a context switch.

A protothread is driven by repeated calls to the run()-function in which the protothread is running. Each time the function is called, the protothread will run until it blocks or exits. Thus the scheduling of protothreads is done by the application that uses protothreads.

For other examples take a look in the examples folder in the MODM root folder.

Warning
The names ptState and ptYield are reserved and may not be used as variables or function names!

Member Function Documentation

bool modm::pt::Protothread::isRunning ( ) const
inline

Check if the protothread is still running.

Returns
true if the protothread is running or waiting, false if it has ended or exited.
void modm::pt::Protothread::stop ( )
inline

Stop the protothread from running.

Happens automatically at PT_END.

Note
This differs from the Dunkels' original protothread behavior (his restart automatically, which is usually not what you want).

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