#include #include #if BUG #define P(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) #else #define P(fmt, ...) printf(fmt, ##__VA_ARGS__) #endif void* go(void *arg) { long tid = (long)arg; P("Thread %ld started\n", tid); for (int i=0; i < 100; i++) P("%ld\n", tid+i); P("Thread %ld exited\n", tid); return 0; } int main() { int tcount = 3; pthread_t tids[tcount]; for (int i=0; i < tcount; i++) pthread_create(&tids[i], 0, &go, (void*)(1000*i)); for (int i=0; i < tcount; i++) pthread_join(tids[i], 0); return 0; }