static void Main(string[] args)
        {
            Garfo    g  = new Garfo();
            Filosofo f1 = new Filosofo(0, g);
            Filosofo f2 = new Filosofo(1, g);
            Filosofo f3 = new Filosofo(2, g);
            Filosofo f4 = new Filosofo(3, g);
            Filosofo f5 = new Filosofo(4, g);

            Thread t1 = new Thread(new ThreadStart(f1.ThreadProc));
            Thread t2 = new Thread(new ThreadStart(f2.ThreadProc));
            Thread t3 = new Thread(new ThreadStart(f3.ThreadProc));
            Thread t4 = new Thread(new ThreadStart(f4.ThreadProc));
            Thread t5 = new Thread(new ThreadStart(f5.ThreadProc));

            t1.Start();
            t2.Start();
            t3.Start();
            t4.Start();
            t5.Start();

            Console.WriteLine("Statou as threads!!!!!!!!!!!!!");

            t1.Join();
            t2.Join();
            t3.Join();
            t4.Join();
            t5.Join();
        }
示例#2
0
        public Filosofo(int idFilosofo, Garfo listGarfos)
        {
            Random rnd = new Random();

            this.idFilosofo  = idFilosofo;
            this.listGarfos  = listGarfos;
            this.tempoComer  = rnd.Next(1000, 2000);
            this.tempoPensar = rnd.Next(1000, 2000);

            if (this.idFilosofo == Constants.qtdeGarfos - 1)
            {
                this.garfoDir = (this.idFilosofo + 1) % Constants.qtdeGarfos;
                this.garfoEsq = this.idFilosofo;
            }
            else
            {
                this.garfoDir = this.idFilosofo;
                this.garfoEsq = (this.idFilosofo + 1) % Constants.qtdeGarfos;
            }
        }