예제 #1
0
        public ThreadContext(ISyncList list, int numOperations, Barrier barrier, double readProportion, LongHistogram latencies)
        {
            SyncList         = list;
            NumOperations    = numOperations;
            Latencies        = latencies;
            Barrier          = barrier;
            OperationResults = new int[10];
            isRead           = new bool[numOperations];
            var r = new Random();

            for (int i = 0; i < numOperations; ++i)
            {
                isRead[i] = r.NextDouble() < readProportion;
            }
        }
예제 #2
0
        private static ThreadContext[] StartThreads(ISyncList list, int numThreads, int numOperations, Barrier barrier, double readProportion)
        {
            var threads  = new Thread[numThreads];
            var contexts = new ThreadContext[numThreads];

            for (int i = 0; i < numThreads; ++i)
            {
                threads[i] = new Thread(new ParameterizedThreadStart(Thread))
                {
                    IsBackground = true
                };
                var latencies = i == 0 ? new LongHistogram(TimeStamp.Seconds(1), 3) : null;
                var context   = new ThreadContext(list, numOperations, barrier, readProportion, latencies);
                contexts[i] = context;
                threads[i].Start(context);
            }
            return(contexts);
        }