void *Sector(void *arg)
{
while (activ != 0) {
printf("-> %d\n", total);
usleep(500000);
}
}
void *Thread_main(void *arg)
{
int i, j, k;
int prim;
int num = 0;
struct thr_parameter *p = arg;
activ++;
printf("Worker %d: Ready for Service\n", p->thr_num);
printf("Worker %d: ", p->thr_num);
printf("Starting calculation from %d to %d\n", p->start, p->end);
for (i = p->start; i <= p->end; i++) {
if (i == 1)
continue;
else if (i == 2 || i == 3)
prim = 1;
else {
prim = 1;
k = sqrt(i);
for (j = 2; j <= k; j++) {
if (i % j == 0) {
prim = 0;
break;
} }
}
if (prim) {
total++;
num++;
}
}
printf("Worker %d: Found %d Primes\n", p->thr_num, num);
activ--;
}
int main(int argc, char *argv[])
{
int threads = 0;
int l = 0;
int i = 1;
int sektor1 = 1;
int sektor2 = 0;
int maximum;
int j;
double diff;
It appears to count prime numbers up to some limit called maximum. It uses multiple threads to do it. There are two command line arguments: -N lets you specify the maximum prime. -T lets you specify how many threads to use. Try running it with these command line options. It should help you figure out how it works: