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
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?
Remove one of the offending lines of code and rebuild the program. Indicate which line you removed. What does
helgrind
report?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.)Examine the code of the
main-deadlock.c
program to see if you can determine what the problem is. What doeshelgrind
report?Examine the code of the
main-deadlock-global.c
program. Does it have the same problem as themain-deadlock.c
program? Doeshelgrind
report the same error?Examine the code of the
main-signal.c
program. The code uses a variabledone
to signal that the child is done and the parent can continue. Why is this code inefficient?Run
helgrind
on themain-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:
assignment5.txt
– the answers to the questionsmain-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.