Some of you know I've been wanting the coroutine/continuation support for better async handlers in Samba.
I've just read Ralf Engelschall's seminal "Portable Multithreading" paper, which led to GNU Pthreads, and realised that he has enough in there to do proper portable coroutine support in vala without dependencies on particular event driven frameworks. Rather than needing vala to declaring continuation structs to hold automatic variables (which doesn't entirely solve the problem), it works by allocating a new stack context from that point, which of course automatically holds all automatic variable. If the stack is allocated with mmap specifying that the region is to be allocated as it is used, then we can be memory efficient without having to worry about running out of stack. As useful starting points I suggest: libcoro - coroutines using Ralphs methods http://software.schmorp.de/pkg/libcoro.html coroutine usage based on libcoro - Jurg may be familiar with this one http://felipec.wordpress.com/2008/09/28/continuations-in-c-easy-asynchronous-stuff/ Bug asking for fibers in GLib, mentioning the above two links http://bugzilla.gnome.org/show_bug.cgi?id=565501 Libfiber - simple fiber library http://www.rkeene.org/projects/info/wiki/22 PhuckThreads - thin skin around Ralph Engelschall's examples https://lunastorm.dyndns.org/svn/PhuckThreads/ Implementing a thread library - See makecontext and longjmp implementations http://evanjones.ca/software/threading.html Windows setcontext stuff in case we need it http://www.codeproject.com/KB/threads/ucontext.aspx Of course we don't want a thread library, but coroutines are pretty much directly scheduled fibres. To continue a co-routine, just call sched_thread(thread_stack_ptr) - which nicely requires calling a function that takes a single pointer - something compatible with most callback types. I'll be trying something like this on Samba and I expect it to be straightforward, but not quite so simple for Vala, unless Vala intends to support fibers? With this method, "yield" will switch back to the main context, and should only be called from a co-routine context. Something must generate the co-routine instance. In samba it happens explicitly when the function consciously decides to defer execution of a specific task, but I'm not sure if this carries over well to some vala examples where yield might be used during io selection and so forth. I haven't seen any vala examples where a corouting instance is generated. I hope someone knows what I'm talking about and speaks out. Sam _______________________________________________ Vala-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/vala-list
