Пример #1
0
void source(struct args *p) {
        int i = 2;

        if (Chan_send(p->c, &i, sizeof i))
                for (i = 3; Chan_send(p->c, &i, sizeof i); i += 2)
                        ;
}
Пример #2
0
int source(void* cl)
{
    struct args* p = cl;
    int i = 2;

    if (Chan_send(p->c, &i, sizeof i))
        for (i = 3; Chan_send(p->c, &i, sizeof i);) {
            i += 2;
        }

    return EXIT_SUCCESS;
}
Пример #3
0
void filter(int primes[], Chan_T listen, Chan_T output) {
        int i, j, n = sizeof i;

        while (n) {
                Chan_receive(listen, &i, sizeof i);
                for (j = 0; primes[j]; j++)
                        if (i%primes[j] == 0)
                                break;
                if (primes[j] == 0)
                         n = Chan_send(output, &i, sizeof i);
        }
        Chan_receive(listen, &i, 0);
}
Пример #4
0
void filter(int primes[], Chan_T input, Chan_T output)
{
    int j, x;

    for (;;) {
        Chan_receive(input, &x, sizeof x);

        for (j = 0; primes[j] != 0 && x % primes[j] != 0; j++)
            ;

        if (primes[j] == 0)
            if (Chan_send(output, &x, sizeof x) == 0) {
                break;
            }
    }

    Chan_receive(input, &x, 0);
}