Пример #1
0
        //[Benchmark(Description = "SimpleStmTask")]
        public int StartStmTasks()
        {
            var variable = new StmRef <int>(0);

            List <Task> taskList = new List <Task>();

            taskList.Add(
                Task.Run(() =>
            {
                Stm.Do <int>(new TransactionBlock <int>(
                                 (IStmTransaction <int> stmTransaction) =>
                {
                    variable.Set(2, stmTransaction);
                    int temp = variable.Get(stmTransaction);
                    temp    += 3;
                    variable.Set(temp, stmTransaction);
                }
                                 ));
            })
                );

            Task.WaitAll(taskList.ToArray());

            return(variable.Value);
        }
Пример #2
0
        public void StmTasksWithManyVariables()
        {
            int countTask      = 5;
            int countVariables = 10;

            StmRef <int>[] variable = new StmRef <int> [countVariables];

            for (int i = 0; i < variable.Length; ++i)
            {
                variable[i] = new StmRef <int>(i);
            }
            int[] randomNumbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };


            List <Task> taskList = new List <Task>();

            for (int i = 0; i < countTask; ++i)
            {
                StmRef <int> tempRef = variable[randomNumbers[i]];
                taskList.Add(
                    Task.Run(() =>
                {
                    Stm.Do <int>(new TransactionBlock <int>(
                                     (IStmTransaction <int> stmTransaction) =>
                    {
                        int temp = tempRef.Get(stmTransaction);
                        temp    += (10 * i);
                        tempRef.Set(temp, stmTransaction);
                    }
                                     ));
                })
                    );
            }

            Task.WaitAll(taskList.ToArray());
        }
Пример #3
0
        //[Benchmark(Description = "ReadingStmTasks")]
        public int StartReadingStmTasks()
        {
            var variable = new StmRef <int>(0);

            List <Task> taskList = new List <Task>();

            taskList.Add(
                Task.Run(() =>
            {
                Stm.Do <int>(new TransactionBlock <int>(
                                 (IStmTransaction <int> stmTransaction) =>
                {
                    int[] temp = new int[10];
                    for (int i = 0; i < 10; i++)
                    {
                        temp[i] = variable.Get(stmTransaction);
                    }
                }
                                 ));
            })
                );

            taskList.Add(
                Task.Run(() =>
            {
                Stm.Do <int>(new TransactionBlock <int>(
                                 (IStmTransaction <int> stmTransaction) =>
                {
                    int[] temp = new int[10];
                    for (int i = 0; i < 10; i++)
                    {
                        temp[i] = variable.Get(stmTransaction);
                    }
                }
                                 ));
            })
                );

            taskList.Add(
                Task.Run(() =>
            {
                Stm.Do <int>(new TransactionBlock <int>(
                                 (IStmTransaction <int> stmTransaction) =>
                {
                    int[] temp = new int[10];
                    for (int i = 0; i < 10; i++)
                    {
                        temp[i] = variable.Get(stmTransaction);
                    }
                }
                                 ));
            })
                );

            taskList.Add(
                Task.Run(() =>
            {
                Stm.Do <int>(new TransactionBlock <int>(
                                 (IStmTransaction <int> stmTransaction) =>
                {
                    int[] temp = new int[10];
                    for (int i = 0; i < 10; i++)
                    {
                        temp[i] = variable.Get(stmTransaction);
                    }
                }
                                 ));
            })
                );

            taskList.Add(
                Task.Run(() =>
            {
                Stm.Do <int>(new TransactionBlock <int>(
                                 (IStmTransaction <int> stmTransaction) =>
                {
                    int[] temp = new int[10];
                    for (int i = 0; i < 10; i++)
                    {
                        temp[i] = variable.Get(stmTransaction);
                    }
                }
                                 ));
            })
                );

            Task.WaitAll(taskList.ToArray());

            return(variable.Value);
        }