int main()
{
    int i = 0;
    mythread_t tid[10];
    void *status;

    // initialize key
    mythread_key_create(&name_key, free);
    mythread_key_create(&id_key, free);

    for (i = 0; i < 10; i++) {
	int *temp = (int *) (malloc) (sizeof(int));
	*temp = i;
	mythread_create(&tid[i], NULL, hello, (void *) temp);
	mythread_yield();
    }

    printf("main thread is joining with child threads\n");
    for (i = 0; i < 10; i++) {
	mythread_join(tid[i], &status);
	printf("joined on thread:%d\n", tid[i]);
    }
    
    mythread_key_delete(id_key);
    mythread_key_delete(name_key);
    printf("main thread is exiting\n");
    fflush(NULL);
    mythread_exit(NULL);
    return 0;
}
int main(int argc, char **argv)
{
	mythread_t thread[MAX_THREADS];
	int rc=0, i;
	struct threadValues *value;

	for(i=0; i < MAX_KEYS; i++)
	{
		rc = mythread_key_create(&keys[i], NULL);
  		if(rc != 0)
			write(1,"\nmythread_key_create() failed\n",29);
   	}

  	printf("Create threads\n");

	for (i=0; i < MAX_THREADS; ++i)
	{
       		value = (struct threadValues *)malloc(sizeof(struct threadValues));
     		value->v1 = i;
     		value->v2 = i+10;
     		rc = mythread_create(&thread[i], NULL, thread_function, value);
     		if(rc != 0)
			printf("\nmythread_create() call error");
  	}

  	printf("Wait for half the threads to complete\n");
  	for (i=0; i < MAX_THREADS; ++i) {
  		rc = mythread_join(thread[i], NULL);
		if(rc != 0)
	     		printf("\nmythread_join() call error\n", rc);
  	}

	//delete half the keys
	for(i=0; i < MAX_KEYS; i++)
	{
		rc = mythread_key_delete(keys[i]);
		if(rc != 0)
	     		printf("\nmythread_delete() call error\n", rc);
	}
  	printf("Main before exiting\n");

        mythread_exit(0);

	//delete other half of the keys
	for(i=MAX_KEYS/2; i < MAX_KEYS; i++)
		mythread_key_delete(keys[i]);
  	printf("Main after exiting\n");
}