To identify and resolve deadlock in a threaded program.
This lab will deal with the 03-deadlock.c program. This program simulates bank account transactions. It keeps an array of bank account balances, and an array of mutexes to lock each account.
The program takes input files that contain lines of the following form:
from to amount
Which specifies that the "from" account should transfer "amount" to the "to" account.
For example, this line:
1 3 75.00
Indicates that account 1 should transfer $75.00 to account 3.
The program uses 4 accounts numbered (0, 1, 2, 3) and spawns four threads to perform these transactions. Use the following test files:
Each thread will open its file, and perform the transactions one by one until it hits the end. It must lock each account it touches before executing a transaction.
However, this program can deadlock! If you run it enough times, it will at some point hang forever.
Your job is to figure out why and fix it!
#!/bin/bash for i in $(seq 1 100) do ./a.out done
Copyright © 2022 Ian Finlayson | Licensed under a Attribution-NonCommercial 4.0 International License.