CS 0449 – pthreads Lab
Due: Friday, August 3, 2012 by Midnight
Make a program with two threads. Note: Remember to compile your program with the -pthread option.
In the first thread, make an infinite loop that does:
printf(“Hello from thread 1 - A\n”);
printf(“Hello from thread 1 - B\n”);
In the second thread, do an infinite loop that does:
printf(“Hello from thread 2 - A\n”);
printf(“Hello from thread 2 - B\n”);
Run the program, and eventually stop it with CTRL+C. The time between thread switches is called a quantum.
1.) Does the quantum seem long or short?
2.) What happens if you insert a pthread_yield() into each loop between the two printf calls?
Now, put a mutex around the two prints and the yield in each thread.
3.) What is the output like?
You need to submit:
Make a tar.gz file as in the first assignment, named USERNAME-lab6.tar.gz
Copy it to ~jrmst106/submit/449/ by the deadline for credit.