Question: To create one thread, I did like this:

```
void *routine(void *i){....}

pthread_t thread1;
pthread_create(&thread1, NULL, routine, NULL);

```

Now I want to create 100 threads and all of them execute `routine`, do I have to do like below? Is it possible to use a for loop?

```
pthread_t thread1;
pthread_t thread2;
...
pthread_t thread100;

pthread_create(&thread1, NULL, routine, NULL);
pthread_create(&thread2, NULL, routine, NULL);
....
pthread_create(&thread100, NULL, routine, NULL);

```

Answer: 
You can create an array of threads

```
#define NTHREADS 100
pthread_t th[NTHREADS];
int i;
for (i=0;i<NTHREADS;++i)
    pthread_create(&th[i],...);

```
Just take `pthread_t thread_arr[100];`(array of threads). Work it out as you work with single thread\_t variable. Use pthread\_arr[1], pthread\_arr[2]... as individual variables.