[REBOL] Lightweight threading / task system impl. questions
From: m::koopmans2::chello::nl at: 1-Feb-2002 10:13
Hi All,
In my rewrite o Rugby I am cuurently incorporating a "task" system. It works
like a queue of code blocks of which one is executed when there is no IO for
a certain time.
This may be very useful for others as well, so.... I would like to expose
that set in a programmer-friendly way. Normally you'd have interruptable
threads with a certain state associated, and you would have to be sure that
your IO does not block athread (i.e. prevent it from receiving an interupt).
In a functional-style eavluator you'd have to count reductions (and weight
them), which is hard with natives....
My current way would be to implement task that executes a certain set of
code and hands control back to the Rebol process itself.
Something like:
task [signature]
[
some-code ;
suspend;
some-other code;
suspend;
label demo;
some-code
suspend/on-return demo
]
The suspend would put you back in the queue (with state preserved).
suspend/on-return with the label will allow for repetetive code blocks in a
task. The drawback is obvious: you have to think about how to partition your
code in a task. OTOH, you *are* in control.
I would typically add a few non-blocking IO operations, such as fetch-web,
fetch-file etc. that you could use in your tasks to make sure that IO
doesn't hang-up a task.
My questions:
- Is this workable?
- what IO operations should be available at least?
- what other blocking operations can you think of?
As this is a side effect of Rugby the task system will be there. Depending
on the feedback and usefullness it will be visible.
--Maarten