コード例 #1
0
ファイル: TestMTStmtIterate.cs プロジェクト: ikvm/nesper
        private void TrySend(int numThreads, int numRepeats, EPStatement[] stmt)
        {
            BasicExecutorService threadPool = Executors.NewFixedThreadPool(numThreads);

            Future <bool>[] future = new Future <bool> [numThreads];
            for (int i = 0; i < numThreads; i++)
            {
                ICallable <bool> callable = new StmtIterateCallable(i, _engine, stmt, numRepeats);
                future[i] = threadPool.Submit(callable);
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(TimeSpan.FromSeconds(5));

            for (int i = 0; i < numThreads; i++)
            {
                Assert.IsTrue(future[i].GetValueOrDefault());
            }
        }
コード例 #2
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;
            }
        }