CS 372 Operating Systems
You need to write three methods: Start(int i, K), AddMemory(int i, A) and Terminate(int i). You can assume each process id i is unique. Use an array memory[i] to keep track of the current memory in use by process i. To keep your solution as simple as possible, do not allocate or bounds check it. You can also assume all requests satisfy the constraints above (i.e., your code should not check that the process always requests less than M amount of memory).
public class BankAccounts{ private int accounts; public class synchronized void Account () { private int total; private boolen busy; ... Account(...) { ... } public synchronized void transfer( Account withdraw, Account deposit, int amount) { withdraw.busy = true; deposit.busy = true; withdraw.transaction(--amount); deposit.transaction(amount); withdraw.busy = false; deposit.busy = false; } public synchronized void transaction(int amount) { while (busy) wait(); if (amount > 0) total+= amount; else (total < -amount) throw new InsufficientFundException() else total -= amount; } }