コード例 #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 T Read(StmRef <T> source)
 {
     try
     {
         return(stmTransaction.Read(source));
     }
     finally
     {
         logger.ReadLog <T>(MethodBase.GetCurrentMethod(), stmTransaction.Revision, stmTransaction.GetParentTransactionRevision(), source);
     }
 }
コード例 #3
0
        private bool CheckStmRefIsBelongToSubTransactions(StmRef <T> stmRef)
        {
            bool result = false;

            foreach (IStmTransaction <T> transaction in subTransactionList)
            {
                if (stmRef.Version == transaction.Revision)
                {
                    result = true;
                }
            }
            return(result);
        }
コード例 #4
0
        public T Read(StmRef <T> stmRef)
        {
            if (!inTxDict.ContainsKey(stmRef))
            {
                RefTuple <T, long> tuple = stmRef.content;

                inTxDict.Add(stmRef, tuple.Value);
                if (!version.ContainsKey(stmRef))
                {
                    version.Add(stmRef, tuple.Version);
                }
            }
            return((T)inTxDict[stmRef]);
        }
コード例 #5
0
 public void Write(StmRef <T> stmRef, T value)
 {
     if (!inTxDict.ContainsKey(stmRef))
     {
         inTxDict.Add(stmRef, value);
         toUpdate.Add(stmRef);
     }
     else
     {
         inTxDict[stmRef] = value;
         if (!toUpdate.Contains(stmRef))
         {
             toUpdate.Add(stmRef);
         }
     }
     if (!version.ContainsKey(stmRef))
     {
         version.Add(stmRef, stmRef.Version);
     }
 }
コード例 #6
0
        public void Write(StmRef <T> stmRef, T value)
        {
            RefTuple <T, long> tuple = stmRef.content;

            if (!inTxDict.ContainsKey(stmRef))
            {
                inTxDict.Add(stmRef, value);
                toUpdate.Add(stmRef);
            }
            else
            {
                inTxDict[stmRef] = value;
                if (!toUpdate.Contains(stmRef))
                {
                    toUpdate.Add(stmRef);
                }
            }
            if (!version.ContainsKey(stmRef))
            {
                version.Add(stmRef, tuple.Version);
                parentVersion.Add(stmRef, tuple.ParentVersion);
            }
        }
コード例 #7
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());
        }
コード例 #8
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);
        }
コード例 #9
0
 public void Write(StmRef <T> target, T newValue)
 {
     stmTransaction.Write(target, newValue);
     logger.WriteLog(MethodBase.GetCurrentMethod(), stmTransaction.Revision, stmTransaction.GetParentTransactionRevision(), target, newValue);
 }
コード例 #10
0
ファイル: Logger.cs プロジェクト: VladimirZhdan/MPP_STM
        public void WriteLog <T>(MethodBase method, long revision, StmRef <T> stmRef, T newValue) where T : struct
        {
            string outputString = ("Transaction №" + revision + " - " + method.Name + "; OldValue = " + stmRef.Value + "; NewValue = " + newValue + "; version = " + stmRef.Version);

            logsQueue.Enqueue(outputString);
        }
コード例 #11
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);
        }
コード例 #12
0
        public void WriteLog <T>(MethodBase method, long revision, long parentRevision, StmRef <T> stmRef, T newValue) where T : struct
        {
            string outputString = ("Transaction №" + revision);

            if (parentRevision != -1)
            {
                outputString  = ("\t" + outputString);
                outputString += ("(Parent - " + parentRevision + ")");
            }
            outputString += (" - " + method.Name + "; variable: " + stmRef.ToString() + "; NewValue = " + newValue);
            logsQueue.Enqueue(outputString);
            //OutputLog(outputString);
        }