Table of Contents
File test.c that you have to download in your current directory.
Answer the following questions:
Read the helgrind documentation. What kind of errors does helgrind detect?
Generate an executable from test.c
(compiling with the option-lpthread
of the gcc) and run it with helgrind. What information about errors is given?
Specify the line in which the program fails.
Files helloThreads.c and race.c that you have to download in your current directory.
Compile helloThreads.c
, run it several times and understand how it works.
Based on the previous example of threads creation, race.c
introduces a counter that is shared among the threads and incremented by them. Compile race.c
and execute it several times. What is the final value of the counter? Why does it happen? Fix the code by using mutex. You can use helgrind to understand and detect problems.
Optionally: modify race.c
to add a new thread that waits until the count variable reaches a specified value (COUNT_LIMIT
) (Recomendation: use helgrind to detect errors).