Introduction to PThreads | |
This lab introduces basic synchronization concepts through the use of
PThreads. We discuss basic usage of PThreads (creating, destroying,
waiting on) and also illustrate (and debug) a simple race condition.
| |
LAB MATERIALS | |
LAB ASSIGNMENT |
You need to complete the implementation of ptcount.c. When you are finished, the main process of
ptcount should create three pthreads and wait for
these pthreads to complete execution. Each thread should increment (in a
loop) a shared variable named count as well as a
local counter. When the child threads are finished executing, the main
thread should print out the value of count. The
value reported by the main process should be consistent with what you would
expect with the given loop bound and increment values. Your program should
match the following output:
bash$ make test ./ptcount 100000 1 Thread: 0 finished. Counted: 100000 Thread: 1 finished. Counted: 100000 Thread: 2 finished. Counted: 100000 Main(): Waited on 3 threads. Final value of count = 300000. Done. After you have finished your implementation, you need to complete a short report that answers the following questions:
make tar |