Skip to content

Instantly share code, notes, and snippets.

@AbhinavPradeep
Created June 30, 2020 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbhinavPradeep/69c5cadc0db98135da061dd70fd725cc to your computer and use it in GitHub Desktop.
Save AbhinavPradeep/69c5cadc0db98135da061dd70fd725cc to your computer and use it in GitHub Desktop.
using System;
using System.Threading;
namespace MultiThreadedProgramming
{
class Account
{
public Account()
{
Balance = 0.00;
Padlock = new Object();
}
public Double Balance{get; private set;}
public Object Padlock;
public void Withdraw(double Amount)
{
lock (Padlock)
{
System.Console.WriteLine($"Trying to withdraw ${Amount}");
if (Balance >= Amount)
{
Thread.Sleep(10000);
Balance -= Amount;
System.Console.WriteLine($"Balance left after withdrawl = ${Balance}");
}
else
{
System.Console.WriteLine($"Sorry you only have ${Balance} left");
}
}
}
public void Deposit(double Amount)
{
Balance+= Amount;
System.Console.WriteLine($"Balance = ${Balance}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment