Threads

Due:
11:00pm, Friday March 11, 2022

Description

For this assignment we will inspect and modify some simple multi-threaded programs and use a tool called helgrind to find problems in these programs.

Questions

  1. Build the main-race.c program using the makefile. Examine the code to see if you can determine where the data race is. Run the command:

    valgrind --tool=helgrind ./main-race

    Does it indicate the correct lines of code for the data race? What other information does it provide?

  2. Remove one of the offending lines of code and rebuild the program. Indicate which line you removed. What does helgrind report?

  3. Add a lock around around both both updates to the shared variable and rebuild the program. What does helgrind report? (The lock API is covered in the Thread API chapter of the textbook.)

  4. Examine the code of the main-deadlock.c program to see if you can determine what the problem is. What does helgrind report?

  5. Examine the code of the main-deadlock-global.c program. Does it have the same problem as the main-deadlock.c program? Does helgrind report the same error?

  6. Examine the code of the main-signal.c program. The code uses a variable done to signal that the child is done and the parent can continue. Why is this code inefficient?

  7. Run helgrind on the main-signal.c program. What does it report? Is the code correct?

Turning in the Assignment

For this assignment, you must turn in a zip file of a directory named assignment5.zip containing the following files:

  1. assignment5.txt – the answers to the questions
  2. main-race.c – the modified program with locks added from question 3

Submit the zip file to the appropriate folder on D2L.

Note that your answers must be correctly numbered and only the answers must be in your assignment5.txt; any answer solution that does not satisfy these requirements will be marked as a zero.

Here is the command to create a zip file of a directory on the Linux server:

zip -r <directory name>.zip <directory name>

where <directory name> is a placeholder for name of the directory that you want to zip.