/* ==== test_wait.c ============================================================
 * Description : Test context switch functionality.
 *
 */

#include <pthread.h>
#include <stdio.h>

char *buf = "abcdefghijklimnopqrstuvwxyz";
int fd = 1;

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

	for (i = 0; i < 10; i++) {
		write(fd, buf + (int)arg, 1);
		sleep(1);
	}
	wait(0);
}

main()
{
	pthread_t thread;
	int i, count = 2;
        int ret;

	pthread_init();

	printf("Going to sleep\n");
	sleep(10);
	printf("Done sleeping\n");

	for(i = 0; i < count; i++) {
		if (pthread_create(&thread, NULL, new_thread, i)) {
			printf("error creating new thread %d\n", i);
		}
	}
	ret = system("ls -l;sleep 3;ls -l /");
        printf("ret=%d \n", ret);
	pthread_exit(NULL);
	fprintf(stderr, "pthread_exit returned\n");
	exit(1);
}
