Professional Documents
Culture Documents
Lab 5 Write-up
The function go() has a parameter arg passed to it and these variables are per thread.
The compiler stores these variables in its own stack in the same address space.
The main() has a local variable i which is in a shared state and is stored in the main()
stack.
There is an obvious bug in step 1. Because go() is outside of the main(), the i values
need to be allocated to the heap. When go() tries to access i values in the stack, it is
unable to. The i values have to be dynamically allocated in the heap using malloc().
Once the values of i’s have been dynamically allocated to the heap, the program will run
correctly as shown in Step 2: