by halayli · 13y ago · 0 comments
Example:
void my_function(void* arg)
{
char buf[1024];
int ret = lthread_recv_exact(fd, buf, 1024, 0, timeout);
lthread_compute_begin();
/* block as long as you wish, run heavy computation on buf, access your stack variables etc.. */
lthread_compute_end();
}
Disclaimer: lthread author.Just to comment on your post, as using blocking calls in coroutine might be a nice feature I think it defeats the whole concept of coroutine. I might be missing the point but this kind of library is absolutely great for asynchronous network calls and in this specific case the library provides a whole set of functions like read/write/connect/accept etc...
I like the idea of being able to schedule coroutines on multiple threads though. In librinoo, I have the concept of 'scheduler'. A scheduler handles a set of coroutines and you can one scheduler per thread (that I called 'spawning').
Those libs are just awesome to quickly create scalable network programs. Well done.
assert(doSomethingThatChangesState() == 0);
throughout your code? I thought the point of assert was for debugging purposes and you should never change program state inside the assertion.If you want to define NDEBUG when compiling lthread, that's up to you.