#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS 5
void *thread_routine(void *data)
{
// you can't just access 'data' directly - it is changing down below!
// 'num' makes a local copy
int num = (int)data;
printf("I am thread %d\n", num);
pthread_exit(NULL);
}
int main(int argc, int* argv[])
{
int i;
pthread_t t[NUM_THREADS];
for (i = 0; i < NUM_THREADS; i++)
{ pthread_create(&t[i], NULL, thread_routine, (void *)i);
}
pthread_exit(NULL);
}