コード例 #1
0
ファイル: PrinterMain.cs プロジェクト: Rvaler/PDP_TF
        static void Main(string[] args)
        {
            int numberResources = 5;                                 // Número de impressoras
            int numberThreads   = 100;                               // Número de threads

            PrinterManager pm = new PrinterManager(numberResources); // Inicializa o genrenciador de recursos

            // Inicialização as threads que iram consumir os recursos
            List <Thread> lstThreads = new List <Thread>(numberThreads);

            for (int i = 0; i < numberThreads; i++)
            {
                lstThreads.Add(new Thread(new PrinterConsumer("Thread_" + i, pm).run));
            }

            // Executa as threads
            foreach (Thread pc in lstThreads)
            {
                pc.Start();
            }

            // Aguarda o término das threads
            foreach (Thread pc in lstThreads)
            {
                pc.Join();
            }

            System.Console.WriteLine("Finished...");
            System.Console.Read();
        }
コード例 #2
0
ファイル: PrinterConsumer.cs プロジェクト: Rvaler/PDP_TF
 /// <summary>
 /// Construtor do consumidor de impressora.
 /// </summary>
 /// <param name="name">Nome que identifica o consumidor de impressora</param>
 /// <param name="pm">Gerenciador de impressoras na qual será consumido uma impressora</param>
 public PrinterConsumer(String name, PrinterManager pm)
 {
     this.name = name;
     this.pm   = pm;
 }