#include <pthread.h>
#include <unistd.h>
#include <errno.h>

pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

void *
thread(void *arg)
{
   int i;

   for (i = 0; i < 5; i++) {
       pthread_mutex_lock(&mutex);
       printf("In thread\n");
       pthread_mutex_unlock(&mutex);
       sleep(5);
   }
   return NULL;
}

main()
{
   int args[2];
   int status;
   pthread_t child;
   int i;
   void *result;

   args[0] = 0;
   args[1] = 0;

   pthread_mutex_init(&mutex);

   if (pthread_create(&tid, NULL, &thread) != EOK) {
	printf("Couldn't create child\n");
   }
   for (i = 0; i < 10; i++) {
       pthread_mutex_lock(&mutex);
       printf("In main()\n");
       pthread_mutex_unlock(&mutex);
       sleep(1);
   }
   status = (int)pthread_join(tid, &result);
   exit(0);
}
