Q: Save identifiers of pthreads in array I have this C program that creates a thread tree using pthreads. Every thread has 2 children. If you run the program with the command line argument "3" the recursion stops when the number of leaves are 8 (2^3). So the recursion stops at 2^n.
Right now when the recursion is finished the leaves of the tree outputs their thread id. However, I want to be able to output the thread id of the leaf's ancestors and itself in order. As an example, if running with the argument n = 3 the output would be 
T1.1 T2.1 T3.1 T4.1
T1.1 T2.1 T3.1 T4.2
T1.1 T2.1 T3.2 T4.3
T1.1 T2.1 T3.2 T4.4
T1.1 T2.2 T3.3 T4.5
T1.1 T2.2 T3.3 T4.6
T1.1 T2.2 T3.4 T4.7
T1.1 T2.2 T3.4 T4.8

Where Tx.x is the different thread-ids.
I tried implementing this using a global array but the problem is that this one gets shared between all the threads and not just the parent thread and its children.
    #include <pthread.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <math.h>
    #include <time.h>

    void checkArguments(int nbrOfArg);
    void* thread_generation(void* arg_param);
    int calculateStop(int n);

    struct arg_t {
        int arg1; // number of threads created
        int arg2; // when to stop creating new children
    };

    int main(int argc, char *argv[]){
        int n;
        n = atoi(argv[1]);
        checkArguments(2);
        struct arg_t args;

        args.arg1 = -1;
        args.arg2 = calculateStop(n);

        thread_generation(&args);
    }

    void* thread_generation(void* arg_param){
        int i;
        pthread_t childrenID[2];
        struct arg_t *args;

        args = (struct args_t*) arg_param;
        args->arg1 = args->arg1 + 1; // 1 more thread created

        if(args->argv1 > args->arg2){ // if true end recursion
            printf("Thread %ld \n", pthread_self());
            pthread_exit(NULL); 
        } else {
            for(i = 0; i < 2; i++){
                pthread_create(&childrenID[i], NULL, thread_generation, (void *) args); // create new thread 
            }
            for(i = 0; i < 2; i++){
                pthread_join(childrenID[i], NULL); // make parent wait for children
            }
        }
    }

    /** Checks so command line argument is valid **/
    void checkArguments(int nbrOfArg){
        if(nbrOfArg != 2){
            fprintf(stderr, "Wrong number of arguments");
            exit(-1);
        }
    }

/** Calculates when the last level of tree is reached and no new children should be created **/   
    int calculateStop(int n){
        int sum = 0;
        for(int i = 1; i < n; i++){
            sum += pow(2, i);
        }
        return sum;
    }

