Hi,
I'm evaluating Nimrod for possible use on a project. I see that it has yield with generators, but does it have proper coroutine support? Or something similar for lightweight threads/fibers?
Best regards, Russ
The manual contains an example how to setup a tasking system: http://nimrod-code.org/manual.html#first-class-iterators
We also have C#-like async/await macros in the works which provide a nicer syntax than iterator x {.closure.} but it didn't make it into 0.9.2.
Most helpful would be if all of your stacks live in a single contiguous block of memory. Then things become much easier.
I'm willing to provide you all the necessary GC hooks to make it work. Things would be easier if you join the IRC channel, but in any case, just tell me what route you want to try.
I've successfuly used posix makecontext/swapcontext (fairly portable, no need for crazy custom libraries) in Nimrod, however only refcounting gc seems to work reasonably.
Options:
I've successfuly used posix makecontext/swapcontext (fairly portable, no need for crazy custom libraries) in Nimrod, however only refcounting gc seems to work reasonably.
That sounds you got lucky, it can't work reliably without write barrier modifications.
Indeed I lucked out. Calling GC_fullCollect explicitly will trigger crash with all gc (ie choice of gc only modifies the likelyhood of something bad happening).
some time ago i came across very crafty coroutine implementation in c++ - boost asio coroutines: http://www.boost.org/doc/libs/1_54_0_beta1/boost/asio/coroutine.hpp this intrigued me a lot because this implementation does not use any expensive context switching, jong jumps, assembly, is 100% portable and has tiny tiny overhead of 1 integer to keep coroutine state. as i needed more features i extended it to have coroutines called automatically and added sleep support. http://paste2box.com/s/#/file/0KHVsFa-ehXFTxPhFoIdOaDgRcc/frAQBc8Wsa.h/?p=0eBouBE2zxVdbSCrxHxBuG2RAIgX disclaimer: its crude and hasty implementation of things i needed and its no longer cross-platform, but then again i needed it on windows. this is just an example.
so.. cant nimrod do something like this too? the only ugly thing is that programmer has to manually call reenter(coroutine_context){} and it should contain coroutine code. and only limitation - local variables can be declared before reenter(), but not inside. essentially reenter() is a switch and each yeld() is case, so thats the reason.