//[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); }
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()); }
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); }