Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- namespace ConsoleApplication1
- {
- public class Program
- {
- static object obj = new object();
- static int bilans = 1100;
- static void Main(string[] args)
- {
- Thread t1 = new Thread(new ThreadStart(Dodaj));
- Thread t2 = new Thread(new ThreadStart(Odejmij));
- t1.Start();
- t2.Start();
- }
- static void Dodaj()
- {
- lock (obj)
- {
- for (int i = 1; i <= 20; i++)
- {
- lock (obj)
- {
- bilans += 100;
- Console.WriteLine(bilans);
- }
- }
- }
- }
- static void Odejmij()
- {
- lock (obj)
- {
- for (int i = 1; i <= 20; i++)
- {
- lock (obj)
- {
- bilans -= 100;
- Console.WriteLine(bilans);
- }
- }
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement