コード例 #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);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: VladimirZhdan/MPP_STM
        private static int StartSubStmTasks()
        {
            var variable1 = new StmRef <int>(0);
            var variable2 = new StmRef <int>(0);

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

            taskList.Add(
                Task.Run(() =>
            {
                StmModified.Do <int>(new TransactionBlockModified <int>(
                                         (IStmTransaction <int> stmTransaction) =>
                {
                    variable1.Set(2, stmTransaction);
                    int temp = variable1.Get(stmTransaction);
                    temp    += 3;
                    variable2.Set(temp, stmTransaction);
                    List <Task> subTaskList = new List <Task>();
                    subTaskList.Add(
                        Task.Run(() =>
                    {
                        StmModified.Do <int>(new TransactionBlockModified <int>(
                                                 (IStmTransaction <int> subStmTransaction) =>
                        {
                            subStmTransaction.SetParentTransaction(stmTransaction);
                            int subTemp = variable1.Get(subStmTransaction);
                            variable2.Set(subTemp, subStmTransaction);
                        }
                                                 ));
                        //TODO subTask
                    })
                        );

                    subTaskList.Add(
                        Task.Run(() =>
                    {
                        StmModified.Do <int>(new TransactionBlockModified <int>(
                                                 (IStmTransaction <int> subStmTransaction) =>
                        {
                            subStmTransaction.SetParentTransaction(stmTransaction);
                            variable1.Set(3, subStmTransaction);
                        }
                                                 ));
                    })
                        );

                    Task.WaitAll(subTaskList.ToArray());
                    //TODO task
                }
                                         ));
            })
                );

            taskList.Add(
                Task.Run(() =>
            {
                StmModified.Do <int>(new TransactionBlockModified <int>(
                                         (IStmTransaction <int> stmTransaction) =>
                {
                    variable1.Set(2, stmTransaction);
                    int temp = variable1.Get(stmTransaction);
                    temp    += 3;
                    variable2.Set(temp, stmTransaction);
                    List <Task> subTaskList = new List <Task>();
                    subTaskList.Add(
                        Task.Run(() =>
                    {
                        StmModified.Do <int>(new TransactionBlockModified <int>(
                                                 (IStmTransaction <int> subStmTransaction) =>
                        {
                            subStmTransaction.SetParentTransaction(stmTransaction);
                            int subTemp = variable1.Get(subStmTransaction);
                            variable2.Set(subTemp, subStmTransaction);
                        }
                                                 ));
                        //TODO subTask
                    })
                        );

                    subTaskList.Add(
                        Task.Run(() =>
                    {
                        StmModified.Do <int>(new TransactionBlockModified <int>(
                                                 (IStmTransaction <int> subStmTransaction) =>
                        {
                            subStmTransaction.SetParentTransaction(stmTransaction);
                            variable1.Set(3, subStmTransaction);
                        }
                                                 ));
                    })
                        );

                    Task.WaitAll(subTaskList.ToArray());
                    //TODO task
                }
                                         ));
            })
                );

            Task.WaitAll(taskList.ToArray());

            return(variable1.Value);
        }