public lfdllOperationExecutor(
     ExecutionSequenceParameters eParams,
     ILockFreeDoublyLinkedList <ListItemData> list, Counter counter,
     int name)
 {
     this.eParams = eParams;
     this.counter = counter;
     Name         = name;
     state        = new LfdllExecutionState(list);
     state.AddToKnownNodes(list.Head);
     state.AddingToKnownNodes(list.Tail);
 }
Exemplo n.º 2
0
 public LfdllExecutionState(
     ILockFreeDoublyLinkedList <ListItemData> list)
     : base(list)
 {
 }
Exemplo n.º 3
0
        runOnLfdll(TestIterationParameters parameters)
        {
            ILockFreeDoublyLinkedList <ListItemData> lfdll
                = LockFreeDoublyLinkedLists.LockFreeDoublyLinkedList.
                  Create <ListItemData>();

            Random initializationRandom
                = new Random(parameters.InitializationSeed);

            foreach (int o in Enumerable.Range(0, parameters.InitialListLength))
            {
                lfdll.PushRight(
                    new ListItemData(
                        o, initializationRandom.Next(listItemValueRange)));
            }

            var timer = new Counter();

            List <lfdllOperationExecutor> executors =
                parameters.OperationSequences.Select(
                    (operationParams, name) =>
                    new lfdllOperationExecutor(operationParams, lfdll,
                                               timer, name)).ToList();

            foreach (lfdllOperationExecutor executor in executors)
            {
                executor.Initialize();
            }

#if SynchronizedLfdll
            List <AutoResetEvent> nextStepWaitHandles = executors.Select(
                executor => new AutoResetEvent(false)).ToList();
#endif

            var executorTasks = new List <Task <List <operationTiming> > >();
            for (int i = 0; i < executors.Count; i++)
            {
                lfdllOperationExecutor executor = executors[i];
#if SynchronizedLfdll
                AutoResetEvent nextStepWaitHandle = nextStepWaitHandles[i];
#endif
                Task <List <operationTiming> > task = new Task <List <operationTiming> >(
                    () =>
                {
                    List <operationTiming> timings;
#if HandleTaskExceptionImmediately
                    try
                    {
#endif
#if SynchronizedLfdll
                    lfdll.NextStepWaitHandle.Value
                        = nextStepWaitHandle;
#endif
                    timings = executor.Run();
#if SynchronizedLfdll
                    lfdll.NextStepWaitHandle.Value.WaitOne();
                    nextStepWaitHandles.Remove(
                        lfdll.NextStepWaitHandle.Value);
                    lfdll.StepCompletedWaitHandle.Set();
#endif
#if HandleTaskExceptionImmediately
                }
                    catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                    Console.WriteLine("Exception in Thread " + Thread.CurrentThread.Name);
                    throw;
                }
#endif
                    return(timings);
                });
                executorTasks.Add(task);
            }

            foreach (Task <List <operationTiming> > task in executorTasks)
            {
#if RunOperationsSequentially
                task.RunSynchronously();
#else
                task.Start();
#endif
            }

            Random executionRandom = new Random(parameters.ExecutionSeed);
#if SynchronizedLfdll_verbose
            List <int> handleIndexes = new List <int>();
#endif

#if SynchronizedLfdll
            while (true)
            {
                if (nextStepWaitHandles.Count == 0)
                {
                    break;
                }
                int nextHandleIndex = executionRandom.Next(nextStepWaitHandles.Count);
#if SynchronizedLfdll_verbose
                handleIndexes.Add(nextHandleIndex);
#endif

                AutoResetEvent nextHandle
                    = nextStepWaitHandles[nextHandleIndex];
                nextHandle.Set();
                lfdll.StepCompletedWaitHandle.WaitOne();
            }
#endif

            // ReSharper disable once CoVariantArrayConversion
            Task.WaitAll(executorTasks.ToArray());

#if SynchronizedLfdll_verbose
            Console.WriteLine(string.Join(" ", handleIndexes));
#endif

            return(new Tuple <List <List <operationTiming> >,
                              ILockFreeDoublyLinkedList <ListItemData> >(
                       executorTasks.Select(t => t.Result).ToList(), lfdll));
        }