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

pthread_t t1,t2;  /* thread process descriptor */
int i1,i2;

/**
 * Create two threads and show I/O mesh
 *
 * Note: not easy to show due to buffer in IO
 *
 * Compilation at linux:   gcc -lpthread pthread2.c -o pthread2
 * Compilation at solaris: gcc -lpthread pthread2.c -o pthread2
 * exe file will be pthread 1 or 2
 */

void * thread_body(void * aparm)
{
  int i,j;
  j = (int)aparm;
  for (;;)
    {
      printf("A");
      printf("B");
      printf("C");
      printf("D");
      printf("E");
      printf("F");
      printf("G");
      printf("H");
      printf("I");
      printf("J");
      printf("K");
      printf("L");
      printf("M");
      sleep(1);
      printf("N");
      printf("O");
      printf("P");
      printf("Q");
      printf("R");
      printf("S");
      printf("T");
      printf("U");
      printf("V");
      printf("X");
      printf("A");
      printf("Z");
      printf("1");
      printf("2");
      printf("3");
      printf("4");
      printf("4");
      printf("5\n");
    }
}

int main(int argc, char *argv[])
{
  int i;
  int res;
  printf("\nHello out there\n");
  printf("I have been called with %i parms\n", argc);

  printf("creating a thread NOW\n");

  /* create thread nr 1 and and transfer "1" to the thread */
  res = pthread_create(&t1,NULL,thread_body,(void *)1);

  /* create thread nr 1 and and transfer "2" to the thread */
  res = pthread_create(&t2,NULL,thread_body,(void *)2);

  for (i=0;i<argc;i++) 
  {
    printf("arg %i: %s\n",i,argv[i]);
  }
  sleep(10);
}
