coroutine

What are use-cases for a coroutine?

The concept of a coroutine sounds very interesting, but I don't know, if it makes sense in a real productive environment? What are use-cases for coroutines, that can be solved more elegant, simpler or more efficient as with other methods? ...

What is coroutine?

What is coroutine? How is it related to concurrency? ...

Python generators and co-routines.

Can someone provide me with a brief introduction on how to use Python generators to implement coroutines? ...

Is it safe to yield from within a "with" block in Python (and why)?

The combination of coroutines and resource acquisition seems like it could have some unintended (or unintuitive) consequences. The basic question is whether or not something like this works: def coroutine(): with open(path, 'r') as fh: for line in fh: yield line Which it does. (You can test it!) The deeper co...

Coroutine vs Continuation vs Generator

What is the difference between a coroutine and a continuation and a generator ? ...

Language that supports serializing coroutines

I don't think such support exists in current languages. I think what I want to do could be solved by a "workflow engine". But the problem I have with workflow's is generally they are: Declarative/verbose and I find a imperative style much more succinct Heavyweight, I'll have a lot of simple though diverse little state machines I've i...

Seeking contrived example code: continuations!

So I believe I understand continuations now, at least on some level, thanks to the community scheme wiki and Learn Scheme in Fixnum Days. But I'd like more practice -- that is, more example code I can work through in my head (preferably contrived, so there's not extraneous stuff to distract from the concept). Specifically, I'd like to ...

Coroutines for game design?

I've heard that coroutines are a good way to structure games (e.g., PEP 342: "Coroutines are a natural way of expressing many algorithms, such as simulations, games...") but I'm having a hard time wrapping my head around how this would actually be done. I see from this article that coroutines can represent states in a state machine whic...

Overhead of Mono Tasklet/Co-Routines

Hi, What are the main performance overheads (gc/stack copying...) of the new Mono Continuations/Tasklet framework? How does this overhead (coroutine performance / raw performance) compare to other frameworks such as Lua Coroutine and stackless python? In Mono 2.6 continuation/coroutines support will be added. I built a svn version and...

Design Pattern Alternative to Coroutines

Hi, Currently, I have a large number of C# computations (method calls) residing in a queue that will be run sequentially. Each computation will use some high-latency service (network, disk...). I was going to use Mono coroutines to allow the next computation in the computation queue to continue while a previous computation is waiting f...

Mono Continuations - Memory keeps increasing after store()

Hi, Here's Mono Continuations' continuation_store (...). From looking at the code below, it appears as though store() follows these two branches: cont->saved_stack && num_bytes <= cont->stack_alloc_size use the memory directly else gc free the used memory, and create some new memory. However, the weird thing is if I repeatedly ...

Differences between Coroutines and GoTo?

I always read about the horrible thing that "goto" is. But, todaym reading about the google programming language "Go" http://golang.org/ and i see that it suports Coroutines (Goroutines). The question is: Coroutine == GoTo Or Coroutine != GoTo? Why? ...

In python is there a way to check if a function is a "generator function" before calling it?

Lets say I have two functions: def foo(): return 'foo' def bar(): yield 'bar' The first one is a normal function, and the second is a generator function. Now I want to write something like this: def run(func): if is_generator_function(func): gen = func() gen.next() #... run the generator ... else: func() ...

Fibers in C#: are they faster than iterators, and have people used them?

So I was chatting with a colleague about fibers and turned up this paper from 2003 that describes a implementation of coroutines in C# using the Fiber API. The implementation of Yield in this paper was for .NET 1.1, so it predates the yield return syntax that appeared in .NET 2.0. It definitely looks, at first glance, that the impleme...

How can I do python/ruby/javascript style generators in actionscript?

I want to use coroutines in actionscript to implement a state machine. I'd like to be able to do something like the following function stateMachine():void { sendBytes(0xFFFF); var receiveBytes:ByteArray = yield() sendBytes(receiveBytes); } stateMachine.send( Socket.read() ) like in this blog entry ...

Difference between a "coroutine" and a "thread"?

What are the differences between a "coroutine" and a "thread"? ...

Scripting languages that support fibers/coroutines?

I'd like to start a new network server project in a language that supports concurrency through fibers aka coroutines aka user-mode threads. Determining what exactly are my options has been exceedingly difficult as the term "coroutine" seems to be used quite loosely to mean a variety of things, and "fiber" is used almost exclusively in r...

C nested switches: outer switch's case inside inner switch

I'm adding coroutine support to an interpreter I'm writing and I'd like to do something like the following: typedef enum { bar_stuff, bar_other } Bar; typedef enum { foo_error=-1, foo_none=0, foo_again } Foo_state; Foo_state do_foo(Bar bar,Foo_state foo) { switch(foo) { case foo_none...

Is there a way to implement Caliburn-like co-routines in VB.NET since there's no yield keyword

Note that I'm aware of other yield in vb.net questions here on SO. I'm playing around with Caliburn lately. Bunch of great stuff there, including co-routines implementation. Most of the work I'm doing is C# based, but now I'm also creating an architecture guideline for a VB.NET only shop, based on Rob's small MVVM framework. Everythin...

Coroutines in C#

I am looking to implement co-routines (user schedualed threads) in c#. When using c++ I was previously using fibers. As I see on the internet fibers do not exist in C#. I would like to get simillar functionality. Is there any "right" way to implement coroutines in c#? I have thought of implementing this using threads that aqcuire a si...