Hacker News new | past | comments | ask | show | jobs | submit login
Protothreads (dunkels.com)
43 points by MagerValp on June 5, 2014 | hide | past | favorite | 7 comments



The "Under the Hood" link explains the mechanism: http://dunkels.com/adam/pt/expansion.html


And what if I want to short-circuit "continue;" in my thread's run loop? I suspect that's hidden somewhere in a "Don't do this" set of caveats that I couldn't find. Presumably you can't write switch statements within your threads either.

Interesting pattern though. I see the similarity with Duff's device, but hadn't ever really imagined a use for that outside of confusing SOFT1001 students...


The worst one--which to be fair, is specifically warned against on the site--is that you can't really use local variables.

The technique is useful to a point. I used a similar technique for a project and the inability to use locals threw off new hires (who usually created a bug before understanding why).

The bigger problem than educating new users though was that as the number of threads scales up (or grows in hierarchy) you burn more and more CPU time stacking/unstacking your calls just to get to the check that "whoops, this thread should still have been blocked." Between that and implementing preemption, at some point you just have to buckle down and pay for stacks.


The SenSys'06 paper has all the details:

http://dunkels.com/adam/pt/publications.html

The context for a lot of "wireless sensor networks" discussion in the paper is that Adam's research group was primarily focusing on sensor networks at the time.


Thank you, that additional information is helpful: http://dunkels.com/adam/dunkels06protothreads.pdf

I presume you are the same Muneeb Ali listed as co-author? The website mentioned in your profile seems to be down.


Yes, my linode servers got hacked and were part of a DDoS attack so I took them offline. I need to boot up a new server and soon (-:


This is somewhat similar to how the iterators are implemented in C#, the compiler generates a state machine for the iterator




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: