CS 3733 Operating Systems, Spring 2009 Assignment 5


Due Friday, April 10

Write a main program called wordCountThread that is like the wordCountChild of Assignment 4, but uses threads instead of child processes. Do not communicate using pipes. Use shared variables. Make sure the execution is concurrent and you report results as soon as they are available. Avoid busy waiting. You should not use sleep or one of its variants to avoid busy waiting. You should suspend the process (or thread) until an appropriate event occurs.

As part of your design you must address the following issues. Include with what you turn in answers to each of these questions. Do not write these out by hand. Type them into a file (you do not need to use a word processor) and print the file. The answers to these questions will be a major part of your grade for this assignment.

  1. How does each thread know which file it is to use?
  2. How do you communicate the result (the word count) back to the original thread?
  3. How many different threads output to the screen? If the answer is more than one, how do you handle this?
  4. How does the original thread know when each thread is finished?
    Note that you should not use join since you do not know which thread will finish first.
  5. How do you know when all threads are done?
  6. What synchronization constructs did you use and where did you use them?
  7. Is your output for this assignment identical to the output generated by Assignment 4? If not, explain why.

Handing in your assignment
Use this cover sheet. Consecutively number all of the pages you turn in. Make sure you answer the questions that are on the cover sheet.