30
loading...
This website collects cookies to deliver better user experience
#include "bee.h"
beedef(iter, int n;)
{
for (bee->n = 0; bee->n < 10; bee->n++) {
beeyeld;
}
beereturn;
}
int main(int argc, char *argv[])
{
iter counter = beenew(iter);
while (beefly(counter)) {
printf("%d\n",counter->n);
}
}
bee.h
file (~60 lines of code).beedef(iter, int n;)
{
... // code to be executed here.
beereturn;
}
iter
is the type of bee we are going to define. It will be a pointer type.int n;
this is the list of variables that we want to survive after yelding.beereturn
must always be present and no code can appear after it.beefly()
it starts executing its code until it reaches beereturn
or beeyeld()
. In the first case the task is completed and the bee don't have any work to resume. In the second case, at the next activation, the work will start from the instruction immediately following the beeyeld()
function.for
loop.for (bee->n = 0; bee->n < 10; bee->n++) {
beeyeld;
}
bee
pointer (think of it as if it was self
or this
).iter counter = beenew(iter);
while (beefly(counter)) {
printf("%d\n",counter->n);
}
beefly()
returns whether it can be resumed or not.beenew()
.while(beefly(mybee))
idiom is a simple form of scheduler, you may need some more complex scheduling policy.bee.h
works. But this can be the subject for another post.30