Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Protothreads can be used with or without an underlying operating system to provide blocking event-handlers. Protothreads provide sequential flow of control without complex state machines or full multi-threading.

So if it's still single-threaded, then this is basically a cumbersome async/await right?



Actually, it is a way to represent state machines as 'code'. It is a way of seperating the data from the functions, such that the functions can be 'stopped' and 'continued' in the middle (turning them into coroutines). Each stop point (often hidden in an await) is a state of the state machine represented by the function.


Yes, and here is an implementation: https://github.com/naasking/async.h

Duff’s device along with the __LINE__ trick enables the creation of automatic DFAs useful to generate coroutines, protothreads and async/await alike.




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

Search: