#include #include #include #include #define N 56 static unsigned long *counter[N]; static void sigint(int __attribute__((unused)) sig) { unsigned i; unsigned long sum = 0; for (i = 0; i < N; i++) { sum += *counter[i]; } printf("spinned: %lu\n", sum); exit(0); } static void *spinner(void *ip) { volatile unsigned long *i = ip; while (1) { (*i)++; } return NULL; } int main(void) { unsigned i; for (i = 0; i < N; i++) { if (!(counter[i] = malloc(256))) perror("malloc"), exit(1); } for (i = 1; i < N; i++) { pthread_t th; pthread_create(&th, NULL, spinner, counter[i]); } signal(SIGINT, sigint); spinner(counter[0]); return 0; }