Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Threads and Mutex
C
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
Makefile
README.md
parta
parta.c
partb
partb.c
partc
partc.c
partd
partd.c

README.md

uvu-cs-3060-project-7

Threads and Mutex

  1. Part A: Your program should create the four threads, as directed above. After starting all of the threads, your program should print out the value of count and then terminate. Do not wait for the threads to finish.

  2. Part B: Your program should create the four threads, as directed above. After starting all of the threads, insert the code required to wait for each of the threads to finish. Then print out the value of count.

  3. Part C: This code will be exactly like the code for part B, with one exception. In this program, you should remove, or comment out, the line of code in the thread function sleep(1); As in part B, When all of the threads have terminated, your main() will print out the value of count.

  4. Part D: In this part, use a mutex to make the program work correctly. The final value of count should be 40, and you should make sure that there aren't any race conditions. Put the call to sleep back in incrementCounter.

In this project you will create a simple program that creates and runs four threads. Each thread will run the same code, given below:

   void* incrementCounter( void* m )
   {
       int i;
       for (i = 0; i < 10; ++i)
       {
           int tempValue = count;
           sleep(1);
           tempValue = tempValue + 1;
           count = tempValue;
       }      
       return NULL;
   }
Something went wrong with that request. Please try again.