CS31 Weekly Lab: Week 13

pthreads, cpuinfo, top, debugging pthreads programs

Copy the week 13 files:

$ cd cs31/inclass
$ cp -r ~mauskop/public/cs31/week13/ .
example pthread programs

mutex.c and barrier.c demonstrate how to use a mutex and how to use a barrier, respectively.

CPU information on machines

top and threads

top is a Unix utility that lists information about processes and threads and how they are using resources like memory and CPU. If you run top with no command line options, then it displays per-process statistics. If you run top with -H, top will display statistics for individual threads:

top -H
debugging pthreads programs

Debugging threaded programs can be tricky because there are multiple streams of execution. In general, try to debug with as few threads as possible, and if you use printfs, print out a thread id and call fflush after. You can also put printf's in conditional statements to only have one of the threads print out information (or only some of the threads, or only some of the information, ...).

gdb and pthreads

We are not going to look at this together in lab, but if you want to try using gdb to debug your pthread code, here is some general information about it and an example you can try out: Debugging pthreads programs with gdb.

More detailed information about gdb and pthreads can be found here: gdb and pthreads