HOME

TheInfoList



OR:

A protothread is a low-overhead mechanism for
concurrent programming Concurrent means happening at the same time. Concurrency, concurrent, or concurrence may refer to: Law * Concurrence, in jurisprudence, the need to prove both ''actus reus'' and ''mens rea'' * Concurring opinion (also called a "concurrence"), a ...
. Protothreads function as
stackless Stackless Python, or Stackless, is a Python programming language interpreter, so named because it avoids depending on the C call stack for its own stack. In practice, Stackless Python uses the C stack, but the stack is cleared between function c ...
, lightweight threads, or
coroutines Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed. Coroutines are well-suited for implementing familiar program components such as cooperative ...
, 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 Concurrent means happening at the same time. Concurrency, concurrent, or concurrence may refer to: Law * Concurrence, in jurisprudence, the need to prove both ''actus reus'' and ''mens rea'' * Concurring opinion (also called a "concurrence"), a ...
known as
cooperative multitasking Cooperative multitasking, also known as non-preemptive multitasking, is a style of computer multitasking in which the operating system never initiates a context switch from a running process to another process. Instead, in order to run multiple ...
and, therefore, do not incur
context switch In computing, a context switch is the process of storing the state of a process or thread, so that it can be restored and resume execution at a later point, and then restoring a different, previously saved, state. This allows multiple processes ...
when yielding to another thread. Within a protothread, yielding is accomplished by utilizing
Duff's device In the C programming language, Duff's device is a way of manually implementing loop unrolling by interleaving two syntactic constructs of C: the - loop and a switch statement. Its discovery is credited to Tom Duff in November 1983, when Duff was ...
within a thread's function and an external variable used in within the
switch statement In computer programming languages, a switch statement is a type of selection control mechanism used to allow the value of a variable or expression to change the control flow of program execution via search and map. Switch statements function some ...
. This allows jumping (resuming) from a yield upon another function call. In order to
block Block or blocked may refer to: Arts, entertainment and media Broadcasting * Block programming, the result of a programming strategy in broadcasting * W242BX, a radio station licensed to Greenville, South Carolina, United States known as ''96.3 ...
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 Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed. Coroutines are well-suited for implementing familiar program components such as cooperative ...
, 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 Global means of or referring to a globe and may also refer to: Entertainment * ''Global'' (Paul van Dyk album), 2003 * ''Global'' (Bunji Garlin album), 2007 * ''Global'' (Humanoid album), 1989 * ''Global'' (Todd Rundgren album), 2015 * Bruno ...
, variables. 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 Tom or TOM may refer to: * Tom (given name), a diminutive of Thomas or Tomás or an independent Aramaic given name (and a list of people with the name) Characters * Tom Anderson, a character in ''Beavis and Butt-Head'' * Tom Beck, a character ...
, of
Duff's device In the C programming language, Duff's device is a way of manually implementing loop unrolling by interleaving two syntactic constructs of C: the - loop and a switch statement. Its discovery is credited to Tom Duff in November 1983, when Duff was ...
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." The protothread concept was developed by
Adam Dunkels Adam Dunkels (born 1978) is a Swedish computer scientist, computer programmer, entrepreneur, and founder of Thingsquare, an Internet of things (IoT) product development business. His father was professor of mathematics Andrejs Dunkels. His moth ...
and Oliver Schmidt, based on prior work by
Simon Tatham Simon Tatham (born 3 May 1977) is a British computer programmer. He created and maintains PuTTY, a free software implementation of Secure Shell (SSH) and Telnet for Microsoft Windows and Unix, along with an xterm terminal emulator. He is also ...
and
Tom Duff Tom or TOM may refer to: * Tom (given name), a diminutive of Thomas or Tomás or an independent Aramaic given name (and a list of people with the name) Characters * Tom Anderson, a character in ''Beavis and Butt-Head'' * Tom Beck, a character ...
.


See also

*
Coroutine Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed. Coroutines are well-suited for implementing familiar program components such as cooperative ...
*
Microthread Microthreads are functions that may run in parallel to gain increased performance in microprocessors. They provide an execution model that uses a few additional instructions in a conventional processor to break code down into fragments that execute ...


References


External links


Protothread library in C
used by
Contiki Contiki is an operating system for networked, memory-constrained systems with a focus on low-power wireless Internet of Things (IoT) devices. Extant uses for Contiki include systems for street lighting, sound monitoring for smart cities, radiati ...

Using Protothreads for Sensor Node Programming
A PDF with some in-depth discussion about the use of Protothreads
Protothread library
requiring GCC, includes a thread scheduler modeled on the
UNIX kernel A Unix architecture is a computer operating system system architecture that embodies the Unix philosophy. It may adhere to standards such as the Single UNIX Specification (SUS) or similar POSIX IEEE standard. No single published standard descri ...
(a simplified form of
POSIX The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system- and user-level application programming interf ...
condition variables In concurrent programming, a monitor is a synchronization construct that allows threads to have both mutual exclusion and the ability to wait (block) for a certain condition to become false. Monitors also have a mechanism for signaling other th ...
). This source base also includes a version that supports multiple CPU cores (processors). *eigenclass.org performed a comparison of protothreads against POSIX threads, and found a 400x improvement in spee

Retrieved from Archive.org Oct 2014
C++ ProtothreadSymbian C++ Protothread Implementation
Threads (computing) {{compu-prog-stub