Linked by Thom Holwerda on Sun 18th Jan 2009 11:16 UTC, submitted by anonymous
General Unix Protothreads are a type of extremely lightweight threads - each protothread requires only two bytes of memory - that are usually used for embedded firmware programming, where memory is at a premium. Protothreads combine the low overhead with event-driven programming with the algorithmic clarity of threaded programming.
E-mail Print r 5   · Read More · 16 Comment(s)
Thread beginning with comment 344308
To read all comments associated with this story, please click here.
Small embedded systems
by antab on Mon 19th Jan 2009 05:48 UTC
antab
Member since:
2007-02-25

Protothreads are really useful on small embedded systems using 8/16bit mcu with only a few KB of RAM and no real OS or scheduling to speak of, and i have used them in few AVR based projects.

But I don't see the performance benefits of using it on big hardware with modern OSes. Prototheads cant be scheduled together, so they provide no performance enhancements on multi cpu systems. They probably provide a little boost on single cpu systems compared to using "real" threads.

On the other hand they can be used to simplify event driven programing.

Reply Score: 1

RE: Small embedded systems
by LMRuane on Tue 20th Jan 2009 00:58 in reply to "Small embedded systems"
LMRuane Member since:
2009-01-20

I published a new version of protothreads you may be interested in, linked from the wikipedia page, and also now on Google Code:

http://code.google.com/p/protothread/

We (I work for HP) use it on a system that's much bigger that a small embedded system (a storage appliance running Linux with many GB of memory), and the reason is, as you said, the programming is simpler than event-driven. It has the same performance as event-driven code, and much faster than regular threads (at least the Linux POSIX pthread library). I measured context switch performance to be 135 times as fast, and thread create - destroy to be 643 times as fast.

You are right that protothreads (including my version) can't take advantage of multiple-CPUs.

Another very important advantage of protothreads (over POSIX threads)for us is that we can write deterministic pseudo-random system-level tests that are reproduceable. (The documentation discusses that a little.)

Reply Parent Score: 1

RE: Small embedded systems
by LMRuane on Tue 20th Jan 2009 05:51 in reply to "Small embedded systems"
LMRuane Member since:
2009-01-20

Sorry, I hadn't seen the rest of the comment thread before I posted the previous comment... I didn't realize you were already talking about the protothread implementation I recently published. (The Google Code and SourceForge code is identical; I'll probably make SourceForge refer to Google Code soon.)

Larry Ruane

Reply Parent Score: 1