C++ Saved Program: serene-af

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


class Bank{
int a=1500;  
  
synchronized void withdraw(int a){  
System.out.println("going to withdraw...");  
  
if(this.a<a){  
System.out.println("Less balance; waiting for deposit...");  
try{wait();
}
catch(Exception e){}  
}  
this.a=a;  
System.out.println("withdraw completed...");  
}  
 synchronized void deposit(int a){  
System.out.println("going to deposit...");  
this.a=a;  
System.out.println("deposit completed... ");  
notify();  
}  
}  
class customer {
public static void main(String args[]){  
 Bank b=new Bank();  
new Thread(){  
public void run(){
b.withdraw(1000);
}  
}b.start();  
new Thread(){  
public void run()
{
b.deposit(1500);}  
}b.start();  
}
} 
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs