5 ms·
As explained here [1], it uses a variation of Duff's device. So the claim that Protothreads were invented by Adam Dunkels with support from Oliver Schmidt is sl
by kitd 7y ago
As explained here [1], it uses a variation of Duff's device. So the claim that Protothreads were invented by Adam Dunkels with support from Oliver Schmidt is slightly misleading IMHO.
But fair play for turning it into a working library.
[1] http://dunkels.com/adam/pt/expansion.html http://dunkels.com/adam/pt/expansion.html
- huhtenberg 7y agoDon't be mean like that. Duff's device to ProtoThreads is what a paintbrush is to a painting. One is a construct for conditional loop unrolling, but it takes a stroke of genius to apply it in an absolutely orthogonal way to implement a functional cooperative multithreading with just a handful of macros. Duff's device was nowhere close to be meant for that, so your condescending pat on a back for "turning it into a working library" is completely inappropriate.
- zamadatix 7y agoI'm not very familiar with each but in reading even the Wikipedia article mentions Duff's device can be used to implement coroutines (with references) so I'm not sure the application is as novel as you lead it on to be.
- BubRoss 7y agoNo one is discovering fire here, no reason to get so upset over a hack.
- vnorilo 7y agoWell, I've seen this exact stroke of genius in at least a dozen different code bases, so while it's a good idea, it's not exactly rare.
- kitd 7y agoVery well. In their own About page, they say they are "heavily inspired" by Simon Tathams "Coroutines in C". In fact, it even more closely resembles that than it does the original Duff's Device. So even they admit it isn't entirely their own work, and I still see no reason to claim they "invented" it. edit: my "pat on the back" was absolutely not "condescending". Turning a neat design in theory into a safe, functional implementation is not to be sniffed at.
- armitron 7y agoThis is basically a beautified version of: https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html from 2000.
- mrpippy 7y agoProtoThreads can use Duff's device to implement its "local continuations", but it's not the only implementation. There's an alternate one that uses the "labels as values" feature supported by GCC and Clang, which is much more elegant. In particular, it allows you to have a 'switch' statement inside the protothread.
- gpderetta 7y agoI've tried that, but unfortunately, at least on GCC, taking the address of a label suppresses inlining of the containing function (which is important of you are trying to implement generators, less critical for async functions), so it often generate worst code than the switch statement implementation.
- deleted 7y ago[deleted]