using System using System Collections Generic using System Linq using

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static int numeration = 0;
static object locker = new object();
class Plant
{
int hase, paus , dira , nom;
public Plant(int ps , int hs,int dr){
hase = hs;
paus = ps;
dira = dr;
lock (locker)
{
nom = numeration++;
}
}
public void rost()
{
while (true)
{
lock (locker)
{
if (paus > dira)
{
dira++;
}
else
{
hase++;
if (hase == 1)
{
Console.Write("1");
dira = 0;
}
if (hase == 2)
{
Console.Write("2");
dira = 0;
}
if (hase == 3)
{
Console.Write("3");
dira = 0;
}
if (hase == 4)
{
Console.Write("4");
dira = 0;
}
if (hase == 5)
{
Console.Write("5");
dira = 0;
}
if (hase == 6)
{
Console.Write("6");
dira = 0;
}
if (hase == 7)
{
Console.Write("7");
dira = 0;
}
if (hase == 8)
{
Console.Write("8");
dira = 0;
}
if (hase > 8)
{
hase = 0;
dira = 0;
}
}
}
Thread.Sleep(3);
}
}
}
static void Main(string[] args)
{
for(int i=0; i<10; i++){
int hase = 0, dira = 400, paus = 1000;
Plant h = new Plant(paus, hase, dira);
Thread t = new Thread(h.rost);
t.Start();
}
}
}
}