示例#1
0
        // Start Count threads
        // each thread performs X loops
        // each loop gets a unique number Y from a shared object and performs setVersion in the synchronized block
        // then the thread performs reads, write and read of shared variables, writing the number Y
        // ==> the reads should not see any higher number (unless watemarks reached)
        // ==> reads should produce the exact same result unless setVersion called
        private void TryMT(int numThreads, int numLoops, int numVariables)
        {
            var coord = new VariableVersionCoord(_service);

            int ord = 'A';

            // create variables
            var variables = new String[numVariables];

            for (int i = 0; i < numVariables; i++)
            {
                variables[i] = String.Format("{0}", ((char)(ord + i)));
                _service.CreateNewVariable(null, variables[i], typeof(int).FullName, false, false, false, 0, null);
                _service.AllocateVariableState(variables[i], EPStatementStartMethodConst.DEFAULT_AGENT_INSTANCE_ID, null, false);
            }

            BasicExecutorService threadPool = Executors.NewFixedThreadPool(numThreads);
            var callables = new VariableServiceCallable[numThreads];
            var future    = new Future <bool> [numThreads];

            for (int i = 0; i < numThreads; i++)
            {
                callables[i] = new VariableServiceCallable(variables, _service, coord, numLoops);
                future[i]    = threadPool.Submit(callables[i]);
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(new TimeSpan(0, 0, 10));

            for (int i = 0; i < numThreads; i++)
            {
                Assert.IsTrue(future[i].GetValueOrDefault());
            }

            //Console.Out.WriteLine(service.ToString());
            // Verify results per thread
            for (int i = 0; i < callables.Length; i++)
            {
                int[][] result = callables[i].Results;
                int[]   marks  = callables[i].Marks;
            }
        }
示例#2
0
        public VariableServiceCallable(String[] variables, VariableService variableService, VariableVersionCoord variableVersionCoord, int numLoops)
        {
            _random               = new Random();
            _variables            = variables;
            _variableService      = variableService;
            _variableVersionCoord = variableVersionCoord;
            _numLoops             = numLoops;

            _results = new int[numLoops][];
            for (int ii = 0; ii < numLoops; ii++)
            {
                _results[ii] = new int[variables.Length];
            }

            _marks = new int[numLoops];

            _readers = new VariableReader[variables.Length];
            for (int i = 0; i < variables.Length; i++)
            {
                _readers[i] = variableService.GetReader(variables[i], EPStatementStartMethodConst.DEFAULT_AGENT_INSTANCE_ID);
            }
        }
        public VariableServiceCallable(String[] variables, VariableService variableService, VariableVersionCoord variableVersionCoord, int numLoops)
        {
            _random               = new Random();
            _variables            = variables;
            _variableService      = variableService;
            _variableVersionCoord = variableVersionCoord;
            _numLoops             = numLoops;

            _results = new int[numLoops][];
            for (int ii = 0; ii < numLoops; ii++)
            {
                _results[ii] = new int[variables.Length];
            }

            _marks = new int[numLoops];

            _readers = new VariableReader[variables.Length];
            for (int i = 0; i < variables.Length; i++)
            {
                _readers[i] = variableService.GetReader(variables[i], 0);
            }
        }