Compile and measure the run-time on your system using a large enough loopcount so that it takes a few seconds to run and the final counter value is incorrect, for example:
$ time ./p26 1000000000 main: begin [counter = 0] [0x5652aef6402c] A: begin [addr of i: 0x7f1722289edc] B: begin [addr of i: 0x7f1721a88edc] B: done A: done main: done [counter: 1031589476] [should: 2000000000] real 0m6.312s user 0m12.539s sys 0m0.001s $Copy the run-time measurements into a comment at the end of the C code.
Modify the C code so that the counter update computation (counter = counter + 1) is protected by a mutual exclusion lock using Pthread_mutex_lock() and Pthread_mutex_unlock().
Then measure the run-time using the same loopcount as before and append the run-time measurements to the comment at the end of the C code. In this case the final counter value should be correct, but it may take much longer to run.
Programs must compile with no warnings or errors using: gcc -Wall -pthread
Each source file must start with a comment containing your name and a description.