ã¨ã©ãã¹ããã¹ã®ãµãã
libtaskã¯ãã£ãã«ã«ã対å¿ãã¦ãããã¨ãããã¨ã§ãLimboã§æ¸ããエラトステネスのふるいãC + libtaskã§æ¸ãç´ãã¦ã¿ããPlan9æ¥è¨ã§ã¯ä½åº¦ããã£ãã«ãåãä¸ãã¦ãããããã£ãã«ã¯ã¿ã¹ã¯éã§ã¡ãã»ã¼ã¸ãããåãããããã®éä¿¡æ段ãæä¾ãããchancreateé¢æ°ã®ç¬¬2å¼æ°ã0ãªã®ã§ããããã¡ã¯ä½¿ããªãããããã£ã¦ãããã¿ã¹ã¯ãã¡ãã»ã¼ã¸ãchansendããã¨ãä»ã®ã¿ã¹ã¯ããã®ãã£ãã«ããchanrecvããã¾ã§ããã®ã¿ã¹ã¯ã¯ãããã¯ãããã
ãã£ã±ããåã®æ±ããLimboã®æ¹ãæ¸ãããããªãLimboã§ã¯ãã£ãã«ã«åããã£ã¦ãsend/recvï¼"<-"ã¨ããæ¼ç®åã使ãããï¼ããã°ãããã ãã©ãlibtask(C)ã ã¨ãã¼ã¿åã«å¿ãã¦ãchansend, chansendp, chansendulé¢æ°ã使ãåããå¿ è¦ããããLimboã¨ã®éãã¯ãchannbsend([p|ul])ã¨ãããã³ããããã³ã°çãç¨æããã¦ãããã¨ã ãããã
#include <stdio.h> #include <stdlib.h> #include "task.h" enum { STACK = 32768 }; int max = 100; void sievetask(void *arg) { Channel *c = (Channel *)arg; Channel *nc; int p, n; p = chanrecvul(c); if (p >= max) taskexitall(0); printf("%d\n", p); nc = chancreate(sizeof(int), 0); taskcreate(sievetask, nc, STACK); for (;;) { n = chanrecvul(c); if (n % p) chansendul(nc, n); } } void taskmain(int argc, char **argv) { Channel *c; int i = 2; if (argc == 2) max = atoi(argv[1]); c = chancreate(sizeof(int), 0); taskcreate(sievetask, c, STACK); for (;;) chansendul(c, i++); }