#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>

void* mallocSomething (void* arg)
{
        int** a = (int**) arg;
        *a = malloc(sizeof(int));
        return NULL;
}

void* writeSomething (void* arg)
{
        int* a = arg;
        *a = 42;
        return NULL;
}


void* readSomething (void* arg)
{
        int* a = arg;
        printf ("The value is %d\n", *a);
        return NULL;
}

int main()
{
        int* a = NULL;
        pthread_t t1,t2,t3,t4;
	int collectTids = 0;
	if (collectTids == 0)
	{
		pthread_create(NULL, NULL, mallocSomething, &a);
        	pthread_create(NULL, NULL, writeSomething, a);
        	pthread_create(NULL, NULL, readSomething, a);
	}
	else
	{
		pthread_create(&t1, NULL, mallocSomething, &a);
        	pthread_create(&t2, NULL, writeSomething, a);
        	pthread_create(&t3, NULL, readSomething, a);
	}

        return 0;
}

