/* compile:
 *  gcc -o onetwotest -lpthread -O2 onetwotest.c
 */

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

void * proc_thread(void *arg)
{
	pthread_exit(0);
}

void proc(int id)
{
	pthread_t t;
	int ret;
	int cnt = 0;

	while (1) {
		printf("%d", id);
		ret = pthread_create(&t, 0, proc_thread, 0);
		if (ret) {
			printf("\nproc(%d) pthread_create() failed with %d!\n",
			       id, ret);
			return;
		}
		printf("%d", id);
		ret = pthread_join(t, 0);
		if (ret) {
			printf("proc(%d) pthread_join() failed with %d!\n",
			       id, ret);
			return;
		}
		printf("%d", id);
		fflush(stdout);
		if (++cnt > 100) {
			printf("\n");
			cnt = 0;
		}
	}
}

int main()
{
	pid_t pid;

	pid = fork();
	if (pid == 0)
		proc(2);
	else if (pid == -1) {
		printf("fork() failed!\n");
		return -1;
	} else
		proc(1);
	return 0;
}

