#include <stdio.h>
#include <sys/process.h>


int k = 5; // initialized global
int k1; // uninitialized global
void printa();
void printb() ;
void printc();
main() {

  int i = 1;
  int j = 0 ;
  char p = 'b' ;
  
  
  k1 = 10;
  print("globals in main ");
  putnum(k);
  putnum(k1);
  print("\r\n");
  
  i = thread_create( printa, 0, 11 ) ;
  putnum(i);
  i = thread_create( printb, 0, 11 ) ;
  print(" ");
  putnum(i);
  
  j = 0 ;
  while(j<10) {
    outbyte('a');
    for (i = 0 ; i < 10000; i++) ;
    j++ ;
  }
  
  i = thread_create( printc, 0, 11 ) ;
  print(" ");
  putnum(i);

  outbyte('A');
  j = 0 ;
  while(j<10) {
    outbyte('A');
    for (i = 0 ; i < 10000; i++) ;
    j++ ;
  }
  outbyte ('x'); 
  k = 16;
  k1 = 32;
  print ("globals in main ");
  putnum(k);
  putnum(k1);
  process_exit() ; 
  outbyte('y');
} 

void printb() 
{
  int j = 0, i ;
  int b = 2;

  while(j<10) {
    if( b == 1 )
      outbyte('b'); 
    else if(b == 2 )
      outbyte('B'); 
    else
      outbyte('c'); 
    for (i = 0 ; i < 10000; i++) ;
    j++ ;
  }
  k++;
  k1++;
  print ("globals in thread ");
  putnum(b);
  putnum(k1);
  putnum(k);
  thread_exit() ;
}

void printa() 
{
  int j = 0, i ;
  int b = 1;

  while(j<10) {
    if( b == 1 )
      outbyte('a'); 
    else if(b == 2 )
      outbyte('A'); 
    else
      outbyte('x'); 
    for (i = 0 ; i < 10000; i++) ;
    j++ ;
  }
  k++;
  k1++;
  print ("globals in thread ");
  putnum(b);
  putnum(k1);
  putnum(k);

  while(j < 1000) {
    outbyte('j'); 
    putnum(j);
    j++;
  }
  thread_exit() ;
}

void printc() 
{
  int j = 0, i ;
  int b = 3;

  while(j<10) {
    if( b == 1 )
      outbyte('c'); 
    else if(b == 2 )
      outbyte('C'); 
    else
      outbyte('d'); 
    for (i = 0 ; i < 10000; i++) ;
    j++ ;
  }
  k++;
  k1++;
  print ("globals in thread ");
  putnum(b);
  putnum(k1);
  putnum(k);
  while (j < 1000) {
    putnum(j+0xffff0000);
    j++;
  }

  thread_exit() ;
}

