fibers

Designing efficient C++ code for fibers

How do I utilize fibers best in my game code? Should it only be used to manage nonpreemptive context-switches while loading resources (i.e. files from disk)? Or do I allow all types of game entities to run in a fiber? How do I schedule? C++ or pseudo code samples greatly appreciated! ...

Implementing preemptive microthreads using signal handlers and setjmp/longjmp

I want to implement POSIX compliant microthreads in Linux environment. Basic idea is as follows: Using technique described here, assign new stack space for each fiber. Using setitimer, create timer that will send signals in constant time interval. Signal handler for this timer will act as a scheduler and switch between fibers. The pr...

Best way to deal with sleeping in event handlers in a single-threaded API?

I'm using a non-threadsafe event API. wait() is called, and from that call, event handlers are dispatched. I want to be able to, within an event handler, "sleep" for some time. Currently, I have a scheduler that schedules functions to be called at a later time, and have a bit of a hack that lets me use Scheduler.Sleeper(some_ienumerator)...

Simple neverblock example doesn't work

I'm trying to do something with "neverblock" and I can't seem to get it to work. What I expect: The blocking sleep shouldn't slow down the whole process. I expected to see 5 times "bla" with basically the same timestamp. Ruby: $ ruby --version ruby 1.9.2dev (2010-03-31 trunk 27123) [x86_64-darwin10.2.0] Code: require "neverblock" fi...

Can Ruby Fibers be Concurrent?

I'm trying to get some speed up in my program and I've been told that Ruby Fibers are faster than threads and can take advantage of multiple cores. I've looked around, but I just can't find how to actually run different fibers concurrently. With threads you can dO this: threads = [] threads << Thread.new {Do something} threads << Threa...

State machine in Ruby using Fibers?

hello, I'm trying to get a handle on the new Fiber class in Ruby 1.9 and I read that one of the more common applications for Fibers (and coroutines) is in state machines. Unfortunately my Fiber-fu isn't up to much, so I was hoping one of you could show me a simple statemachine example in Ruby using Fibers thanks :) ...

Fibers in Python

I'm looking for a very simple way to implement fibers in Python. I'm sure there's a really simple way to do it using generators, but my mind is crapping out on me. This isn't for a huge application, so I don't need the fanciness (or the overhead) of something like Diesel or Tornado or Twisted, I just want a neat little way to do fibers. ...