import std.stdio;
import core.thread;
class Bank
{
private int money_;
void payin(int m)
{
money_ += m;
}
void payout(int m)
{
money_ -= m;
if (money_ < 0)
{
throw new Exception("pay out exception.");
}
}
int money() @property
{
return money_;
}
}
void main()
{
auto bank = new Bank;
auto tg = new ThreadGroup;
bool isRunning = true;
tg.create = {
while (isRunning)
{
try
{
if (bank.money >= 100)
{
foreach (_; 0..10000){}
bank.payout(100);
}
}
catch (Exception e)
{
isRunning = false;
throw e;
}
}
};
tg.create = {
while (isRunning)
{
bank.payin(100);
}
};
tg.joinAll();
}