Computer Science 354
Operating Systems
Dickinson College
Spring Semester 2006
John MacCormick
Threads
Reading Assignment
- Operating Systems Concepts: Chapter 4.
Lecture Slides
Homework Assignment
Due Date: 3/17/08
- Operating Systems Concepts: #4.3, #4.4, #4.5.
- Write a Java program that takes two integers as command line parameters and computes the summation of all of the integers from the first parameter up to but not including the second. For example if the parameters were 100 and 8000 then the program would add up all of the integers from 100 up to but not including 8000. Your program must divide the work of computing the summation up among 4 concurrently executing threads. Each thread should compute the summation for approximately 1/4 of the range of numbers and store the result in the shared address space. The
main
thread must wait for all 4 threads to complete. When the threads are complete the main
thread must compute the final result by adding up the partial results generated by the threads and display it on standard output.
- Under what circumstances would the program you just wrote run more quickly than a single threaded solution that did all of the computation in
main
?
Related Web Sites
- Threads: Doing Two Or More Tasks At Once
- A set of pages from the Java Tutorial that discuss how to create and use threads. Some of this goes well beyond what we'll be doing in this class, but the inroductory material is good.
Sample Code
Acknowledgment: this content is essentially identical to that
developed by Professor Grant Braught for the Spring 2006 Operating
Systems course, and I'm grateful for his permission to use it.