views:

196

answers:

1

I just stumbled on Protothreads. They seems superior to native threads since context switch are explicit.

My question is. Makes this multi-threaded programming an easy task again?

(I think so. But have I missed something?)

+5  A: 

They're not "superior" - they're just different and fit another purpose. Protothreads are simulated, and hence aren't real threads. They won't run on multiple cores, and they will all block on a single system call (socket recv() and such). Hence you shouldn't see it as a "silver bullet" that solves all multithreading problems. Such threads have existed for Java, Ruby and Python for quite some time now.

On the other hand, they're very lightweight so they do make some tasks quicker and simpler. They're suitable for small embedded systems because of low code and memory footprint. If you design your whole system (including an "OS", as is customary on small embedded devices) from the ground up, protothreads can provide a simple way to achieve concurrency.

Also read on green threads.

Eli Bendersky
Do web servers use green threads?
Flinkman
I doubt that any serious servers use green threads, because they need blocking IO (socket) calls to operate
Eli Bendersky