/* vim: tabstop=2 expandtab * gcc -Wall -pedantic -std=c99 -ggdb -pthread -o thread thread.c */ #include #include #include #include #include #define POOL_SIZE 2 void* first(void* threadid) { printf("Init thread 1\n"); int i=(int)threadid; while (1) { printf("1st thread: %d\n", i); i++; sleep(1); } pthread_exit(NULL); } void* second(void* threadid) { printf("Init thread 2\n"); int i=(int)threadid; while (1) { printf("2nd thread: %d\n", i); i++; sleep(1); } pthread_exit(NULL); } int main(int argc, char* argv[]) { pthread_t pool[POOL_SIZE]; int i=1; printf("Join first thread\n"); pthread_create(&pool[i], NULL, first, (void*) i); if (errno) printf("errno: %d/%s\n", errno, strerror(errno)); i++; printf("Join second thread\n"); pthread_create(&pool[i], NULL, second, (void*) i); if (errno) printf("errno: %d/%s\n", errno, strerror(errno)); pthread_exit(NULL); return(0); }