libtask/testdelay.c

41 lines
612 B
C
Raw Permalink Normal View History

2009-10-11 00:04:03 +04:00
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <task.h>
enum { STACK = 32768 };
Channel *c;
void
delaytask(void *v)
{
taskdelay((int)(uintptr_t)v);
printf("awake after %d ms\n", (int)(uintptr_t)v);
2009-10-11 00:04:03 +04:00
chansendul(c, 0);
}
void
taskmain(int argc, char **argv)
{
int i, n;
2014-08-03 20:28:37 +04:00
2009-10-11 00:04:03 +04:00
c = chancreate(sizeof(unsigned long), 0);
n = 0;
for(i=1; i<argc; i++){
n++;
printf("x");
taskcreate(delaytask, (void*)(uintptr_t)atoi(argv[i]), STACK);
2009-10-11 00:04:03 +04:00
}
/* wait for n tasks to finish */
for(i=0; i<n; i++){
printf("y");
chanrecvul(c);
}
taskexitall(0);
}