Coroutines in C, Duff's device and Protothreads
September 25 2010, 8:25 AM
All this craziness was started with Duff’s device:
- first Tom Duff’s post to net.lang.c,
- his later explaination in comp.lang.c,
- Wikipedia article on Duff’s device.
Continued with Simon Tatham’s Coroutines in C hack:
- http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
- with a remark on PuTTY’s SSH implementation:
PuTTY is a Win32 Telnet and SSH client. The SSH protocol code contains real-life use of this coroutine trick. As far as I know, this is the worst piece of C hackery ever seen in serious production code.
Finally, this trick was used by Adam Dunkels in a real operating system for embedded devices: