chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] scheduling and coroutines


From: Tomtom
Subject: [Chicken-users] scheduling and coroutines
Date: Fri, 25 Feb 2011 18:06:59 +0100
User-agent: Sup/0.11

Hi list.

First of all, I'm new here and new to scheme too. So please bear with me.

I'm trying to write a pretty simple scheduler that juggles between several
coroutines by using call/cc. I've read that chicken is really good at this,
which is perfect.

here is my first step toward this goal: a simple scheduler that manages a queue
of continuations.

(require-extension symbol-utils)

(define q (make-queue))

(define scheduler
  (lambda ()
    (let loop ()
      (if (not (queue-empty? q))
      (let ((cont (call/cc (queue-remove! q))))
        (if (not (unspecified? cont))
        (queue-add! q cont))
        (loop))))))

(define (routine cont)
  (let loop ((n 10))
    (display n)(newline)
    (set! cont (call/cc cont))
    (if (> n 0)
    (loop (- n 1)))))

(queue-add! q routine)

(scheduler)

It works like a charm, but I'd like to go a step further. I need a scheduling
algorithm a bit more complex: when a coroutine pauses by calling the scheduler,
it should also give a "sleep duration" after which the scheduler will have to
resume the coroutine. That timing information would be used by the scheduler to
insert the continuation at the right place in the queue.

So my problem is: How can I pass the timing information from the coroutine to
the scheduler ? I read that the procedure passed to call/cc should have only
one argument (which will be the current continuation), but I hear rumours about
those mysterious values / call-with-values procedures that have something to do
with all this. Here, it starts to get blurry in my head - can anyone guide me
further down the road ?

cheers

tom



reply via email to

[Prev in Thread] Current Thread [Next in Thread]