Libutask is a simple user-level threads library that is designed to be
extensible for experimenting with scheduling algorithms in user space.The library has a simple API and provides two schedulers, a cooperative and a preemptive one that schedules tasks in a round robin fashion. This is an example of how to use the cooperative scheduler of the library:
#include "utask.h"
/* task callback function */
void task_func(void *arg)
{
volatile int i,c,b;
for (i=0; i<1000; i++) {
/* do some work */
for (c=0; c<1000; c++);
/* yield */
utask_yield();
}
utask_destroy();
}
int main(int argc, char **argv)
{
/* initialize the library using the
default cooperative scheduler*/
utask_init(NULL);
/* create two tasks */
utask_create (
task_func, /* task callback */
NULL, /* task arguments */
16384 /* stack size 16k */
);
utask_create (
task_func,/* task callback */
NULL, /* task arguments */
16384 /* stack size 16k */
);
/* start the scheduler */
utask_run();
return 0;
}
Source code:hg clone https://code.google.com/p/libutask
No comments:
Post a Comment