/*****************************************************/
/* Example code from class using the pthread library */
/*                                                   */
/* To compile me in Linux:                           */
/*    gcc -firstpthread firstpthread.c -lpthread     */
/*                                                   */
/*****************************************************/
#include <stdio.h>
#include <pthread.h>

void *runner(void * param);   /* function that the thread will execute */
int value;

int main() {
  pthread_t tid;
  pthread_attr_t attr;

  pthread_attr_init(&attr);

  value=0;
  printf("In main before creating the thread, value=%d\n",value);

  pthread_create( &tid, &attr, runner, NULL);

  printf("In main thread, value = %d\n", value);

  pthread_join( tid, NULL);  /* makes the main code wait for the thread */

  printf("Main is done, value=%d\n", value);

  return 0;
}

void * runner(void *param)
{
   value = 12;
   printf("In the thread, value = %d\n", value);
   pthread_exit(0);
}
  

