Knowledge

Protothread

Source 📝

306: 92:, 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 106:
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
96:, 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. 107:
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."
294: 347: 371: 82: 284: 289: 58: 340: 366: 283:
eigenclass.org performed a comparison of protothreads against POSIX threads, and found a 400x improvement in speed
277: 43: 333: 62: 50:, providing a blocking context cheaply using minimal memory per protothread (on the order of single bytes). 262: 266: 54: 32: 313: 78: 186: 226: 85:
so that successive calls to the same function will yield unless the guard conditional is true.
69:
when yielding to another thread. Within a protothread, yielding is accomplished by utilizing
103: 74: 70: 280:). This source base also includes a version that supports multiple CPU cores (processors). 93: 158:
Protothreads: Simplifying Event-Driven Programming of Memory-Constrained Embedded Systems
317: 66: 77:. This allows jumping (resuming) from a yield upon another function call. In order to 360: 274: 170: 166: 115: 111: 270: 136: 305: 89: 47: 39: 252: 156: 131: 17: 258: 119: 99: 247: 73:
within a thread's function and an external variable used in within the
162: 255:
A PDF with some in-depth discussion about the use of Protothreads
88:
A feature of protothreads relative to other implementations of
243: 201: 321: 202:"Protothreads - Lightweight, Stackless Threads in C" 253:Using Protothreads for Sensor Node Programming 155:A. Dunkels, O. Schmidt, T. Voigt, and M. Ali, 341: 181: 179: 8: 114:and Oliver Schmidt, based on prior work by 348: 334: 81:threads, these yields may be guarded by a 110:The protothread concept was developed by 148: 295:Symbian C++ Protothread Implementation 53:Protothreads are used to accomplish a 7: 302: 300: 286:Retrieved from Archive.org Oct 2014 187:"Brainwagon » Coroutines in C" 25: 304: 31:is a low-overhead mechanism for 165:, Boulder, CO, USA, Nov 2006. ( 1: 65:and, therefore, do not incur 320:. You can help Knowledge by 388: 372:Computer programming stubs 299: 38:Protothreads function as 244:Protothread library in C 63:cooperative multitasking 316:-related article is a 273:(a simplified form of 33:concurrent programming 314:computer-programming 367:Threads (computing) 278:condition variables 259:Protothread library 171:Presentation slides 329: 328: 227:"Coroutines in C" 16:(Redirected from 379: 350: 343: 336: 308: 301: 267:thread scheduler 231: 230: 223: 217: 216: 214: 212: 197: 191: 190: 183: 174: 153: 75:switch statement 21: 387: 386: 382: 381: 380: 378: 377: 376: 357: 356: 355: 354: 290:C++ Protothread 269:modeled on the 240: 235: 234: 225: 224: 220: 210: 208: 199: 198: 194: 185: 184: 177: 154: 150: 145: 128: 23: 22: 15: 12: 11: 5: 385: 383: 375: 374: 369: 359: 358: 353: 352: 345: 338: 330: 327: 326: 309: 298: 297: 292: 287: 281: 256: 250: 239: 238:External links 236: 233: 232: 218: 200:Adam Dunkels. 192: 175: 147: 146: 144: 141: 140: 139: 134: 127: 124: 67:context switch 42:, lightweight 24: 14: 13: 10: 9: 6: 4: 3: 2: 384: 373: 370: 368: 365: 364: 362: 351: 346: 344: 339: 337: 332: 331: 325: 323: 319: 315: 310: 307: 303: 296: 293: 291: 288: 285: 282: 279: 276: 272: 268: 265:, includes a 264: 260: 257: 254: 251: 249: 245: 242: 241: 237: 228: 222: 219: 207: 203: 196: 193: 188: 182: 180: 176: 172: 168: 164: 160: 159: 152: 149: 142: 138: 135: 133: 130: 129: 125: 123: 121: 117: 113: 108: 105: 104:Duff's device 101: 97: 95: 91: 86: 84: 80: 76: 72: 71:Duff's device 68: 64: 60: 56: 55:non-preempted 51: 49: 45: 41: 36: 34: 30: 19: 322:expanding it 311: 221: 209:. Retrieved 205: 195: 161:, Proc. ACM 157: 151: 116:Simon Tatham 112:Adam Dunkels 109: 98: 87: 52: 37: 28: 26: 18:Protothreads 271:UNIX kernel 206:Dunkels.com 137:Microthread 83:conditional 59:concurrency 29:protothread 361:Categories 261:requiring 143:References 90:coroutines 48:coroutines 211:April 21, 132:Coroutine 61:known as 40:stackless 246:used by 126:See also 120:Tom Duff 100:Tom Duff 57:form of 248:Contiki 44:threads 163:SenSys 94:global 312:This 275:POSIX 102:, of 79:block 46:, or 318:stub 213:2017 118:and 263:GCC 167:PDF 363:: 204:. 178:^ 169:, 122:. 35:. 27:A 349:e 342:t 335:v 324:. 229:. 215:. 189:. 173:) 20:)

Index

Protothreads
concurrent programming
stackless
threads
coroutines
non-preempted
concurrency
cooperative multitasking
context switch
Duff's device
switch statement
block
conditional
coroutines
global
Tom Duff
Duff's device
Adam Dunkels
Simon Tatham
Tom Duff
Coroutine
Microthread
Protothreads: Simplifying Event-Driven Programming of Memory-Constrained Embedded Systems
SenSys
PDF
Presentation slides


"Brainwagon » Coroutines in C"
"Protothreads - Lightweight, Stackless Threads in C"

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.