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

struct in {
  int a;
  int b;
};

struct out {
  int c;
  int d;
};

void *ThreadController (void *arg)
{
  struct in *indata;
  struct out *outdata;

   indata = (struct in *)arg;
   printf("indata is %d and %d\n", indata->a, indata->b);
   
   outdata = (struct out *)malloc(sizeof(struct out));
   outdata->c = indata->a*2;
   outdata->d = indata->b*2;
   pthread_exit(outdata);
   return (NULL); /* we never get here */
}

int main()
{
  int i;
  struct in *a;
  pthread_t tid[3];
  struct out *b;

  for (i=0;i<3;i++) {
    a = (struct in *) malloc (sizeof (struct in));
    a->a = i+1;
    a->b = i+100;
    pthread_create(&tid[i],NULL,ThreadController,a);
  }
  for (i=0;i<3;i++) {
    pthread_join(tid[i],(void **)&b);
    printf("Thread %d returned %d and %d\n",i,b->c, b->d);
  }
  return 0;
}
 
    
