예제 #1
0
        private static void ThreadTest()
        {
            LogThread("Start");

            Order order = CreateOrderTest();

            var product = order.Item as Product;

            if (product != null)
            {
                Operation operation = new AssemblyOperation();

                operation.Log += LogThread;

                // synchroniczne
                // operation.Execute(product)

                // asynchroniczne
                //Thread thread1 = new Thread(() => operation.Execute(product));

                //Thread thread2 = new Thread(() => operation.Execute(product));

                //Thread thread3 = new Thread(() => operation.Execute(product));

                //thread1.Start();

                //thread2.Start();

                //thread3.Start();

                // Utworzenie wątków
                //for (int i = 0; i < 100; i++)
                //{
                //    Thread thread = new Thread(() => operation.Execute(product));
                //    thread.Start();
                //}

                // Pula wątków

                for (int i = 0; i < 100; i++)
                {
                    //ThreadPool.QueueUserWorkItem(Download, "http://www.vavatech.pl");
                    ThreadPool.QueueUserWorkItem(state => operation.Execute(product));
                }
            }
        }
예제 #2
0
        private static void TaskTest()
        {
            LogThread("Start");

            Order order = CreateOrderTest();

            var product = order.Item as Product;

            if (product != null)
            {
                Operation operation = new AssemblyOperation();

                operation.Log += LogThread;

                //Task task = new Task(() => operation.Execute(product));
                //task.Start();

                for (int i = 0; i < 100; i++)
                {
                    Task task = Task.Run(() => operation.Execute(product));
                }
            }
        }
        private AssemblyOperation ParseAssemblyOperation()
        {
            var asterisk = NextToken(false);

            if (asterisk.IsOperator(Operator.Asterisk))
            {
                _stream.Next();
            }
            else
            {
                asterisk = null;
            }

            var reg = ParseRegister();

            var allowedOps = new HashSet <string>()
            {
                Operator.Assign,
                Operator.AssignPlus,
                Operator.AssignMinus,
                Operator.AssignShiftRight,
                Operator.AssignShiftLeft,
                Operator.AssignOr,
                Operator.AssignAnd,
                Operator.AssignXor,
                Operator.AssignLess,
                Operator.AssignGreater,
                Operator.AssignCond
            };
            var op = NextToken();

            if (op.Type != TokenType.Operator || !allowedOps.Contains(op.Value))
            {
                throw SyntaxError.Make(SyntaxErrorMessages.INVALID_TOKEN, op);
            }

            var node = new AssemblyOperation(op);

            if (asterisk != null)
            {
                var deref = new Dereference(asterisk);
                deref.AddChild(reg);

                node.AddChild(deref);
            }
            else
            {
                node.AddChild(reg);

                asterisk = NextToken(false);
                if (asterisk.IsOperator(Operator.Asterisk))
                {
                    _stream.Next();
                }
                else
                {
                    asterisk = null;
                }
            }

            // If we have two dereferences in the statement ParseRegister will fail
            reg = ParseRegister();

            if (asterisk != null)
            {
                var deref = new Dereference(asterisk);
                deref.AddChild(reg);

                node.AddChild(deref);
            }
            else
            {
                node.AddChild(reg);
            }

            if (!op.IsOperator(Operator.Assign) && asterisk != null)
            {
                throw SyntaxError.Make(SyntaxErrorMessages.INVALID_ASM_DEREFERENCE_USE(), node.Position);
            }

            return(node);
        }