Beispiel #1
0
        public void Racebetween2NekaraTasks()
        {
            DeadlockWithNekaraLockAndTask dlk = new DeadlockWithNekaraLockAndTask();

            while (!dlk.bugFound)
            {
                Nekara.Models.Task t1 = Nekara.Models.Task.Run(() => dlk.Foo());
                Nekara.Models.Task t2 = Nekara.Models.Task.Run(() => dlk.Bar());

                Nekara.Models.Task.WaitAll(t1, t2);

                dlk.nekara.Api.WaitForMainTask();
                dlk.Reset();
            }
        }
Beispiel #2
0
        public void Participate(ISiloLifecycle lifecycle)
        {
            Nekara.Models.Task OnStart(CancellationToken ct)
            {
                this.listenToClusterChangeTask = ListenToClusterChange();
                return(Nekara.Models.Task.CompletedTask);
            };
            async Nekara.Models.Task OnStop(CancellationToken ct)
            {
                this.shutdownToken.Cancel();
                if (listenToClusterChangeTask != default && !ct.IsCancellationRequested)
                {
                    await listenToClusterChangeTask.WithCancellation(ct);
                }
            };

            lifecycle.Subscribe(nameof(GrainLocator), ServiceLifecycleStage.RuntimeGrainServices, OnStart, OnStop);
        }
Beispiel #3
0
        public void Deadlock3()
        {
            nekara.Api.CreateSession();
            while (!bugFoundDl)
            {
                nekara.Api.CreateResource(0);
                nekara.Api.CreateResource(1);

                int counter           = 1;
                Nekara.Models.Task t1 = Nekara.Models.Task.Run(() =>
                {
                    nekara.Api.ContextSwitch();
                    Acquire(true, 0);

                    nekara.Api.ContextSwitch();
                    Acquire(true, 1); // Deadlock

                    if (bugFoundDl)
                    {
                        return;
                    }

                    nekara.Api.ContextSwitch();
                    counter++;

                    nekara.Api.ContextSwitch();
                    Release(true, 0);

                    nekara.Api.ContextSwitch();
                    Release(true, 1);
                });

                Nekara.Models.Task t2 = Nekara.Models.Task.Run(() =>
                {
                    nekara.Api.ContextSwitch();
                    Acquire(false, 1);

                    nekara.Api.ContextSwitch();
                    Acquire(false, 0); // Deadlock

                    if (bugFoundDl)
                    {
                        return;
                    }

                    nekara.Api.ContextSwitch();
                    counter--;

                    nekara.Api.ContextSwitch();
                    Release(false, 1);

                    nekara.Api.ContextSwitch();
                    Release(false, 0);
                });

                var t3 = Nekara.Models.Task.WhenAll(t1, t2);

                t3.Wait();
                nekara.Api.WaitForMainTask();

                lck1 = false;
                lck2 = false;
                nekara.Api.CreateSession();
            }

            // Console.WriteLine("  ... Finished Deadlock Benchmark");
        }