Rahul Sharma (Editor)

Protothreads

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

A protothread is a low-overhead mechanism for concurrent programming.

Protothreads function as stackless, lightweight threads providing a blocking context cheaply using minimal memory per protothread (on the order of single bytes).

Protothreads are used to accomplish a non-preempted form of concurrency known as cooperative multitasking and, therefore, do not incur context switch when yielding to another thread. Within a protothread, yielding is accomplished by utilizing Duff's device within a thread's function and an external variable used in within the switch statement. This to allows jumping (resuming) from a yield upon another function call. In order to block threads, these yields may be guarded by a conditional so that successive calls to the same function will yield unless the guard conditional is true. Because protothreads are accomplished by successive calls to a function, they must retain their state through the use of external, often global, variables.

The protothread concept was developed by Adam Dunkels and Oliver Schmidt.

References

Protothreads Wikipedia