A method of concurrency in which the universal primitive is an actor
The running state of an actor is monitored and managed by another actor (the Supervisor)
01| struct Checking { 02| balance int 03| } 04| 05| currentBal = Checking.balance; 06| if( currentBal > withdrawlAmt ) { 07| Checking.balance -= withdrawlAmt; 08| return true; 09| } else { 10| return false; 11| }
01| struct Checking { 02| balance int 03| lock Mutex 04| } 05| 06| Checking.lock.Lock(); 07| currentBal = Checking.balance; 08| if( currentBal > withdrawlAmt ) { 09| Checking.balance -= withdrawlAmt; 10| return true; 11| } else { 12| return false; 13| } 14| Checking.lock.Free();
01| actor Checking { 02| var balance = 80 03| 04| def receive = { 05| case Withdrawl(amt) => 06| if( balance > amt ) { 07| balance -= amt 08| sender sendMsg true 09| } else { 10| sender sendMsg false 11| } 12| } 13| }
01| // send message to withdrawl 60 dollars 02| Checking sendMsg Withdrawl(60) 03| 04| // send message to withdrawl 50 dollars 05| Checking sendMsg Withdrawl(50)