Instructions for Exercise

This lesson demonstrates how you can run files provided in the exercise.

We'll cover the following...

This exercise lets you play around with a number of ways to implement a small, deadlock-free vector object in C. The vector object is quite limited (e.g., it only has add() and init() functions) but is just used to illustrate different approaches to avoiding deadlock.


ALL = vector-deadlock vector-global-order vector-try-wait vector-avoid-hold-and-wait vector-nolock
COMMON = vector-header.h main-common.c main-header.h

all: $(ALL)

clean:
	rm -f $(ALL) *~

vector-deadlock: vector-deadlock.c $(COMMON)
	gcc -o vector-deadlock vector-deadlock.c -Wall -pthread -O

vector-global-order: vector-global-order.c $(COMMON)
	gcc -o vector-global-order vector-global-order.c -Wall -pthread -O

vector-try-wait: vector-try-wait.c $(COMMON)
	gcc -o vector-try-wait vector-try-wait.c -Wall -pthread -O

vector-avoid-hold-and-wait: vector-avoid-hold-and-wait.c $(COMMON)
	gcc -o vector-avoid-hold-and-wait vector-avoid-hold-and-wait.c -Wall -pthread -O

vector-nolock: vector-nolock.c $(COMMON)
	gcc -o vector-nolock vector-nolock.c -Wall -pthread -O

Some files that you should pay attention to are as follows. They, in particular, are used by all the variants in this exercise.

  • mythreads.h: The usual wrappers around many different pthread (and other) library calls, so as to ensure they are not failing silently

  • vector-header.h: A simple header for the vector routines, mostly defining a fixed vector size and then a struct that is used per vector (vector_t) ...