Exemple #1
0
        public RPN(string[] str)
        {
            output = new MyQueue <string>();
            stack  = new MyStack <string>();

            foreach (string s in str)
            {
                int num = 0;
                if (Int32.TryParse(s, out num))
                {
                    output.Push(s);
                }
                else
                {
                    switch (s)
                    {
                    case "+":
                    case "-":
                        if (!stack.IsEmpty() && (stack.Back() == "*" || stack.Back() == "/"))
                        {
                            while (!stack.IsEmpty())
                            {
                                output.Push(stack.Pop());
                            }
                        }
                        stack.Push(s); break;

                    case "*":
                    case "/":
                    case "^":
                        if (!stack.IsEmpty() && (stack.Back() == "*" || stack.Back() == "/"))
                        {
                            output.Push(stack.Pop());
                        }
                        stack.Push(s);
                        break;

                    case "(":
                        stack.Push(s);
                        break;

                    case ")":
                        while (stack.Back() != "(")
                        {
                            output.Push(stack.Pop());
                        }
                        stack.Pop();
                        break;
                    }
                }
            }
            while (!stack.IsEmpty())
            {
                output.Push(stack.Pop());
            }
        }
        //public static Task task2;
        //public static ManualResetEvent a = new ManualResetEvent(false);
        static void Main(string[] args)
        {
            //Action action= new Action(MyFiberProcess.Start);
            //task2 = new Task(action);
            for (int i = 0; i < 2; i++)
            {
                MyQueue.Push(new Task());
            }
            MyFiberProcess main = new MyFiberProcess();

            main.Exit += Exit;
            Fiber FiberFirst = new Fiber(main.Start);

            MyQueue.MainFiber = FiberFirst.Id;
            main.Start();
        }
        public void Start()
        {
            // try

            {
                while (MyQueue.queue.Count() > 0)
                {
                    Task task = MyQueue.Get();
                    if (MyQueue.WorkIn() == null)
                    {
                        Console.WriteLine("Произошёл первый вызов распределительного файбера!");
                    }
                    else
                    {
                        if (MyQueue.WorkIn().IsComplete)
                        {
                            Fiber.Delete(MyQueue.WorkIn().fiberID);
                        }
                        else
                        {
                            MyQueue.Push(MyQueue.WorkIn());
                        }
                    }
                    MyQueue.SetWorkIn(task);
                    if (task.IsWork)
                    {
                        Fiber.Switch(task.fiberID);
                    }
                    else
                    {
                        Fiber fiber = new Fiber(task.process.Run);
                        task.fiberID = fiber.Id;
                        task.IsWork  = true;
                        Fiber.Switch(task.fiberID);
                    }
                }
                //Thread.Sleep(10000);
                // if (MyQueue.first)
                Console.WriteLine("Главный файбер вышел из цикла раздачи в методе!!!");
                Console.ReadKey();
                Exit();
                //можно и так валить прогу
                //можно также просто вызывать метод System.Environment.Exit(0);
                //	Process.GetCurrentProcess().Kill();
            }
            //catch(Exception)он не видит ни каких исключений, выдаёт коды ошибок
        }