• Notice regarding image hosts and attachments. See here.

2nd year comp sci help

Associate
Joined
30 Jun 2003
Posts
2,237
Location
Sussex
I'm revising for my exam and I'm stuck on a question:

how can I rewrite this code to prevent deadlocks:
there are 1000 bank accounts in this multi-threaded system:

P(S[to_debit]);
P(S[to_credit]);
A[to_debit] -= amount;
A[to_credit] += amount;
V(S[to_credit]);
V(S[to_debit]);

where A is a global array shared by all threards showing the balance of accounts
S is an array of semaphors and the other variables are local to each thread.

I get why one can occur, just not how to rewrite it.
 
Back
Top Bottom