📑 Table of Contents

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

Protothreads function as stackless, lightweight threads, or coroutines, 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 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.

A feature of protothreads relative to other implementations of coroutines, or proper threads, is that they are stackless. This has advantages and disadvantages. A disadvantage is that local variables within the protothread cannot be trusted to have retained their values across a yield to another context. They must retain their state through the use of static or external, often global, variables.[1] An advantage is that they are very lightweight and therefore useful on severely memory constrained systems like small microcontrollers where other solutions are impractical or less desirable.

Tom Duff, of Duff's device fame, had this to say about the shortcomings of the method: "a similar trick for interrupt-driven state machines that is too horrible to go into. [...] I never thought it was an adequate general-purpose coroutine implementation because it’s not easy to have multiple simultaneous activations of a coroutine and it’s not possible using this method to have coroutines give up control anywhere but in their top-level routine. A simple assembly-language stack-switching library lets you do both of those."[2]

The protothread concept was developed by Adam Dunkels and Oliver Schmidt,[3] based on prior work by Simon Tatham[4] and Tom Duff.[2]

See also

edit

References

edit
  1. ^ A. Dunkels, O. Schmidt, T. Voigt, and M. Ali, Protothreads: Simplifying Event-Driven Programming of Memory-Constrained Embedded Systems, Proc. ACM SenSys, Boulder, CO, USA, Nov 2006. (PDF, Presentation slides)
  2. ^ a b "Brainwagon » Coroutines in C".
  3. ^ Adam Dunkels. "Protothreads - Lightweight, Stackless Threads in C". Dunkels.com. Retrieved April 21, 2017.
  4. ^ "Coroutines in C".
edit

📚 Artikel Terkait di Wikipedia

Contiki

small-memory systems, the Contiki programming model is based on protothreads. A protothread is a memory-efficient programming abstraction that shares features

Muneeb Ali

dissertation which formed the basis of the Stacks network. He is a co-author of Protothread and Proof-of-Transfer (PoX) consensus. Ali studied Computer Science at

Arduino

version is freely available. There is also a threading tool, named Protothreads. Protothreads are described as "extremely lightweight stackless threads designed

Microthread

Continuation Coroutine Fiber (computer science) Micro-thread (multi-core) Protothread Helmut Grohne (2006). "libmuth tutorial: Microthreads". subdivi.de. Retrieved

Coroutine

Tom Duff in a discussion on its relative merits vs. the method used by Protothreads.[non-primary source needed] On platforms which provide the POSIX sigaltstack

Adam Dunkels

(micro-IP) and lwIP TCP/IP Internet protocol suite (stacks). He invented protothreads and the operating system Contiki. The MIT Technology Review placed him

Comparison of real-time operating systems

security, embedded virtualisation PPC, x86, ARM, MIPS, SPARC-LEON, RISC-V Protothreads BSD open source general purpose active Architecture independent pSOS

Duff's device

Protothreads - Lightweight, Stackless Threads in C also uses nested switch/case statements (see also The lightest lightweight threads, Protothreads)