digitalmars.D - protothreads
- Daniel919 web.de (23/23) Dec 22 2005 Hi, is there a way to build an implementation of protothreads in the D l...
Hi, is there a way to build an implementation of protothreads in the D language ? http://www.sics.se/~adam/pt/ It's a very leightweight way to do event-driven programming. Instead of forking threads, this library (which actually is only precompiler code) helps to build switch statements around the codeblocks you want to be executed asynchronous. To show how easy it can handle complex blocking situations, I will show two lines from the examples included in the library: timer_set(&codelock_timer, 1000); PT_WAIT_UNTIL(pt, key_pressed() || timer_expired(&codelock_timer)); Because D has no precompiler (and I am pretty new to it), I found no way to replace something with incomplete codeblocks like: #define x int a #define y = 10; a y If you look at the source of protothreads, you will see that it's just about 40 lines of C code (ignoring the comments) ! So if an implementation of it can be done for D, wouldn't it be worth it ? Btw, maybe it could be done better in D, for example by using staticif instead of the switch statement (to avoid creating scopes) ? Thanks in advance, Daniel
Dec 22 2005