Advertisement
Guest User

Fork Server

a guest
Feb 16th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6.  
  7. namespace PhilosopherServer
  8. {
  9.     class Program
  10.     {
  11.         const int kNumPhilosophers = 5;
  12.         static String kFork = "Fork";
  13.  
  14.         static void Main(string[] args)
  15.         {
  16.             Semaphore[] forks = new Semaphore[kNumPhilosophers];
  17.             for (int i = 0; i < kNumPhilosophers; i++)
  18.             {
  19.                 String ii = i.ToString();
  20.                 String forkName = kFork + ii;
  21.                 Console.WriteLine(forkName);
  22.                 forks[i] = new Semaphore(5, 5, forkName);
  23.             }
  24.  
  25.             Semaphore kek = new Semaphore(5, 5);
  26.             if (Semaphore.TryOpenExisting("Fork1", out kek))
  27.             {
  28.                 Console.WriteLine("Success");
  29.             }
  30.             else
  31.             {
  32.                 Console.WriteLine("Bad job");
  33.             }
  34.             while(true)
  35.             {
  36.  
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement