bank.c
and map.c
files as email attachments.
In this lab, you will practice using threads and locks to complete the implementation of two simple parallel programs. Both programs include test drivers that will help you determine whether your implementation is working correctly. There are some additional requirements that are not checked by the test programs, so please read the instructions carefully.
All the starter code is available in parallelism.tar.gz. Download and unpack this archive to set up for the lab.
The bank program implements a simple banking simulation. The main bank implementation is in bank.c
; this is where you will make all of your changes. The simple simulation allows users to create accounts, add transactions, transfer money between accounts, and access both the transaction count and current balance for each account. Each account is accessed from a different thread.
Your task for this part of the lab is to fix the bank simulation. If you run the test program using the command make test
, you will see that the banking system tends to lose money and transaction counts. This is because the bank simulation does not use any synchronization operations. You should add locks to the banking system to make sure it does not lose any transactions. However, you may not use a single lock to protect the whole bank! You must allow independent transactions on separate accounts to proceed in parallel.
Please do not change anything in the bank-test.c
and bank.h
files. You are only required to submit bank.c
for this part. I will test it with the original versions of the other two files.
For the second part of the lab, you will implement a parallel version of the familiar map
function from Scheme. The starter code for this part includes a serial implementation, along with a test program that will run your parallel implementation with 1, 2, 4, and 8 threads, and validate all the results.
Your job is to implement parallel_map
. The output from the function must be correct, but you must also adhere to a few additional requirements:
threads
threads in the function. That means you will need to have each thread run the mapped function over more than one entry.parallel_map
. A more advanced implementation might have the main thread do work as well, but please do not do that for this lab.