/* Orion Lawlor's Short UNIX Examples, olawlor@acm.org 2003/8/18
Shows how to create and join pthreads.
*/
#include <stdio.h>
#include <pthread.h>

void *doWork(void *ignored)
{
	int i;
	int b=1,a=1;
	printf("Entered work function...\n");
	fflush(stdout);
	for (i=0;i<100000000;i++)
		b=a+b;
	printf("Leaving work function\n");
	return (void *)b;
}

int main()
{
	pthread_t thA,thB;
	pthread_attr_t pattr;
	
	/*Spawn a bunch of threads*/
	pthread_attr_init(&pattr);
	pthread_create(&thA,&pattr,doWork,NULL);
	pthread_create(&thB,&pattr,doWork,NULL);
	
	/*Catch up to all threads*/
	printf("Joining with first thread...\n");
	pthread_join(thA,NULL);
	printf("Joining with second thread...\n");
	pthread_join(thB,NULL);
	
	return 0;
}

/*<@>
<@> ******** Program output: ********
<@> Entered work function...
<@> Leaving work function
<@> Joining with first thread...
<@> Joining with second thread...
<@> Entered work function...
<@> Leaving work function
<@> */
