Due Date: Monday Oct. 20

1.
a. Run the following program.

#include 
#include 

int count = 0;

void *adder(void *);

int
main(int argc, char **argv) 
{
	int i;
	pthread_t tid[10];
	void *status;

	thr_setconcurrency(10);

	for (i = 0; i < 10; ++i) {
		pthread_create(&tid[i], 0, adder, 0);
	}
	
	for (i = 0; i < 10; ++i) {
		pthread_join(tid[i], &status);
	}

	printf("count = %d\n", count);

	return 0;
}


void *
adder(void *dummy) 
{
	int i;

	for (i = 0; i < 100000; ++i) {
		count++;
	}
}

b. Remove the thr_setconcurrency(10) line and run the program.

c. Add code to create the threads with system scope contention (recall that process scope contention is the default) and run the program.

d. Explain the results.

2. Write a program that takes multiplies arbitrary size square matrices using threads. The command line arguments should be the size of the matrices and the number of threads to use. The program will prompt for the elements of the input matrices, and display the output matrix.

3. Write a program to apply sets of transactions, stored in multiple files, to a set of accounts. Each file contains lines of the form:

account number, transaction type, amount

Where account number is a number between 1 and 10, transaction type is "credit" or "debit", and amount is a floating point number.

Your program should take the names of transaction files as command line arguments and create a thread to process each transaction file. Note that each account may have transactions in more than one transaction file. The initial balance in each account is 0. The program should display the account balances after all transactions have been performed.

Finally, the program should be implemented in a manner that maximizes the amount of parallel computation possible while still computing the correct answer.