[dmd-concurrency] draft 7
Michel Fortin
michel.fortin at michelf.com
Mon Feb 1 06:17:52 PST 2010
Hum, say I want to implement a synchronized Bank class as a collection of bank accounts:
synchronized class Bank {
private BankAccount[name] accounts;
private string[] log;
void addAccount(string name) {
accounts[name] = new BankAccount();
log ~= "account created";
}
void transferMoney(string from, string to, uint amount) {
BankAccount first = accounts[from];
BankAccount second = accounts[to];
synchronized (first, second) {
first.withdraw(amount);
second.deposit(amount);
log ~= "money transfer successful";
}
}
void removeAccount(string name) {
accounts.remove(name);
log ~= "account removed";
}
}
Where am I going to need casts here?
Also, which parts are going to be done using atomic operations?
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the dmd-concurrency
mailing list