Guest User

Untitled

a guest
May 24th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. namespace ConsoleApplication19
  2. {
  3. class Account
  4. {
  5. private static Object thisLock = new Object();
  6.  
  7. public void Withdraw()
  8. {
  9. lock (thisLock)
  10. {
  11. Console.WriteLine("1");
  12. Thread.Sleep(5000);
  13. }
  14. }
  15. }
  16.  
  17. class Test
  18. {
  19. static void Main()
  20. {
  21. Account a = new Account();
  22. Thread t = new Thread(a.Withdraw);
  23. t.Start();
  24.  
  25. Account b = new Account();
  26. Thread t2 = new Thread(b.Withdraw);
  27. t2.Start();
  28.  
  29. Console.ReadLine();
  30. }
  31. }
  32. }
Add Comment
Please, Sign In to add comment