Slashdot Mirror


Protothreads and Other Wicked C Tricks

lwb writes "For those of you interested in interesting hard-core C programming tricks: Adam Dunkels' protothreads library implements an unusually lightweight type of threads. Protothreads are not real threads, but rather something in between an event-driven state machine and regular threads. But they are implemented in 100% portable ANSI C and with an interesting but quite unintuitive use of the switch/case construct. The same trick has previously been used by Simon Tatham to implement coroutines in C. The trick was originally invented by Tom Duff and dubbed Duff's device. You either love it or you hate it!"

2 of 229 comments (clear)

  1. This is cool. by Anonymous Coward · · Score: -1, Flamebait

    But all you Java lovers will no doubt sneer at it. You suck.

  2. Stupid by Anonymous Coward · · Score: -1, Flamebait

    This is stupid. It uses a bunch of god damn scary macros and will never be as efficient as your operating system's context switching mechanism. No professional software developer would go near this.