#include <stdio.h>
#include <pthread.h>

void sleep_t1(void *name)
{
  int i;
  for(i=0; i<5; i++) {
     printf("%s schläft jetzt!\n",(char *)name);
     sleep(3);
     printf("%s ist jetzt wieder wach!\n",(char *)name);
    }
  pthread_exit((void *) 0);
}

void sleep_t2(void *name)
{
  int i;
  for(i=0; i<5; i++) {
     printf("%s schläft jetzt!\n",(char *)name);
     sleep(1);
     printf("%s ist jetzt wieder wach!\n",(char *)name);
    }
  pthread_exit((void *) 0);
}


int main()
{
 pthread_t t1, t2;

  if(pthread_create(&t1, NULL, (void *)&sleep_t1, (void *)"Thread 1") != 0)
    {
      fprintf(stderr, "Fehler bei Thread 1......\n");
      exit(0);
    }
  if(pthread_create(&t2, NULL, (void *)&sleep_t2, (void *)"Thread 2") != 0)
   {
      fprintf(stderr, "Fehler bei Thread 1......\n");
      exit(0);
   }
  pthread_join(t1, NULL);
  pthread_join(t2, NULL);

  return 0;
}