Learning Objectives
In this assignment you will demonstrate:
- The ability to describe certain principles of concurrent programs
- The ability to explain various Java synchronization objects.
- The ability to write simple concurrent programs in Ada, Java, and Go.
Readings, Videos, and Self-Study
Although your team will be turning in only one submission, every team member is individually responsible for each of the following:
Submission Instructions
Submit to BrightSpace a PDF or text file with:
- Your name.
- An affidavit that each of the assigned readings were completed.
- Answers to each of the exercises below, numbered and neatly typeset. For problems involving code to write, host your code on Replit, JDoodle, ATO, TIO, OneCompiler, or similar hosting platform and provide the link to your program, along with instructions for running the program if the simple Run button does not suffice.
Exercises
- What is the difference between concurrency and parallelism?
- What is the difference between a thread and a task in Java? Give an example.
- In Java, what happens if you invoke a method on a thread that has terminated?
- Give an example of livelock in the programming language of your choice.
- Give an example of deadlock in the programming language of your choice.
- Craft a table that provides information on each of the following Java entities: countdown latches, semaphores, cyclic barriers, exchangers, and phasers. The left column should contain the class names for the five entities. The second column should contain a description, and the third an example of where it would be used (without any code).
- Consider an implementation of the dining philosophers problem in which the first four philosophers always pick up their right chopstick first, but the fifth philosopher always picks up their left chopstick first. Can deadlock occur? Why or why not?
- Write, in Ada, a prime number printing program that constructs, on the fly, a chain of threads, each representing a prime number, which filters out all candidates passed through them. Start with a single thread whose job it is to test inputs for divisibility by 2. If a number is divisible by 2, go back and listen for more inputs. If a number is not divisible by 2, pass it along to the “next” thread. If there is no next thread, create a new thread for that number and assign this new thread as the next thread.
- Repeat the previous exercise in Java.
- Repeat the previous exercise in Go.