예제 #1
0
        public bool CheckDeadlockLivelockFreedom(List <DcrGraph> dcrGraphs)
        {
            DcrGraphs = dcrGraphs;

            CreateRelatedGraph();

            FindDeadlocks();

            FindLivelocks();

            return(!Deadlocks.Any() && !Livelokcs.Any());
        }
예제 #2
0
        private void FindDeadlocks()
        {
            var cycleChecker = new CycleChecker();

            foreach (var dcrGraph in DcrGraphs)
            {
                var cycles = cycleChecker.GetAllCycleConditionMilestone(dcrGraph.Activities);
                if (cycles != null)
                {
                    var breakAble = false;
                    // check any event included and no incoming except include
                    breakAble = dcrGraph.Activities.Any(x =>
                                                        !x.Excluded && x._relationsIncoming.All(y => y.Type == Relation.RelationType.Include));
                    if (breakAble)
                    {
                        return;
                    }

                    // check exists safe event which can not be excluded
                    foreach (var activity in dcrGraph.Activities)
                    {
                        if (activity.IsSafe(dcrGraph) &&
                            activity._relationsIncoming.All(x => x.Type != Relation.RelationType.Exclude))
                        {
                            breakAble = true;
                        }
                    }

                    if (breakAble)
                    {
                        return;
                    }

                    var cyclesBreakAble = new List <bool>();

                    foreach (var cycle in cycles)
                    {
                        breakAble = cycle.Any(x =>
                                              x._relationsIncoming.All(y => y.Type != Relation.RelationType.Include) &&
                                              x._relationsIncoming.All(y =>
                                                                       y.Type == Relation.RelationType.Exclude && y.From.IsSafe(dcrGraph)));
                        cyclesBreakAble.Add(breakAble);
                    }

                    for (var index = 0; index < cyclesBreakAble.Count; index++)
                    {
                        var breakable = cyclesBreakAble[index];
                        if (breakable)
                        {
                            continue;
                        }
                        var cycle = cycles[index];
                        if (cycle.All(x =>
                                      !x.Pending && x._relationsIncoming.All(y => y.Type != Relation.RelationType.Response) && dcrGraph.Activities.All(y => !y.Pending)))
                        {
                            cyclesBreakAble[index] = true;
                        }
                    }

                    for (var index = 0; index < cyclesBreakAble.Count; index++)
                    {
                        var b     = cyclesBreakAble[index];
                        var cycle = cycles[index];
                        if (!b)
                        {
                            Deadlocks.Add(new Tuple <DcrGraph, List <Activity> >(dcrGraph, cycle));
                        }
                    }
                }
            }
        }