Fibers and Coroutines

Aug 8, 2011 at 9:55pm
Has anyone ever used a fibers or coroutines in real life?

I've read about fibers, and played about with them, but never come across a situation where I needed to use them. But there does seem quite a bit of chat about them on the web.

As far as I've worked out so far, they're a way of maintaining multiple stacks to you can reenter a function and carry on where you were. But as you have to explicitlt switch fiber, it looks like the kind of problem I've solved by splitting into subtasks (using task classes) and then scheduled on one or more threads (usually a small pool).

Based on one of the articles I scanned, which described fibers as a form of preemptive multitasking, it almost sounds like a rewind to WIN16 days!

Andy
Aug 8, 2011 at 10:31pm
I've used coroutines in Lua to conveniently describe the behavior of animated objects. Instead of keeping n objects whose states get modified by a function called on each of them, you keep n closures running on coroutines that pause and resume as needed.
Aug 12, 2011 at 5:21pm
Thanks for you reply, Helios. All the other coroutine users must be off elsewhere!

Andy

Aug 12, 2011 at 5:59pm
OO and coroutines/closures are not antithetical, but they do basically the same thing. Pick one system and stick with it. C++ chose OO.
Topic archived. No new replies allowed.