void EntryInit() { var flag = (this.ReceivedEvent as Eflag).flag; var counter = SharedRegister.Create <S>(this.Id.Runtime); counter.SetValue(new S(1, 1)); this.CreateMachine(typeof(N), new E(counter)); counter.Update(x => { return(new S(x.f + 1, x.g + 1)); }); var v = counter.GetValue(); this.Assert(v.f == v.g); // succeeds if (flag) { this.Assert(v.f == 2 || v.f == 5 || v.f == 6); // succeeds } else { this.Assert(v.f == 2 || v.f == 6); // fails } }
private void InitOnEntry(Event e) { var flag = (e as Setup).Flag; var counter = SharedRegister.Create(this.Id.Runtime, 0); counter.SetValue(5); this.CreateActor(typeof(N1), new E <int>(counter)); counter.Update(x => { if (x == 5) { return(6); } return(x); }); var v = counter.GetValue(); if (flag) { // Succeeds. this.Assert(v is 2 || v == 6); } else { // Fails. this.Assert(v == 6, "Reached test assertion."); } }
void EntryInit() { var flag = (this.ReceivedEvent as Eflag).flag; var counter = SharedRegister.Create <int>(this.Id.Runtime, 0); counter.SetValue(5); this.CreateMachine(typeof(N), new E(counter)); counter.Update(x => { if (x == 5) { return(6); } return(x); }); var v = counter.GetValue(); if (flag) { this.Assert(v == 2 || v == 6); //succeeds } else { this.Assert(v == 6); // fails } }
private void InitOnEntry(Event e) { var flag = (e as Setup).Flag; var counter = SharedRegister.Create <S>(this.Id.Runtime); counter.SetValue(new S(1, 1)); this.CreateActor(typeof(N2), new E <S>(counter)); counter.Update(x => { return(new S(x.Value1 + 1, x.Value2 + 1)); }); var v = counter.GetValue(); // Succeeds. this.Assert(v.Value1 == v.Value2); if (flag) { // Succeeds. this.Assert(v.Value1 is 2 || v.Value1 == 5 || v.Value1 == 6); } else { // Fails. this.Assert(v.Value1 is 2 || v.Value1 == 6, "Reached test assertion."); } }
void InitOnEntry() { var flag = (this.ReceivedEvent as Setup).Flag; var counter = SharedRegister.Create <int>(this.Id.Runtime, 0); counter.SetValue(5); this.CreateMachine(typeof(N1), new E <int>(counter)); counter.Update(x => { if (x == 5) { return(6); } return(x); }); var v = counter.GetValue(); if (flag) { // Succeeds. this.Assert(v == 2 || v == 6); } else { // Fails. this.Assert(v == 6); } }
void InitOnEntry() { var flag = (this.ReceivedEvent as Setup).Flag; var counter = SharedRegister.Create <S>(this.Id.Runtime); counter.SetValue(new S(1, 1)); this.CreateMachine(typeof(N2), new E <S>(counter)); counter.Update(x => { return(new S(x.Value1 + 1, x.Value2 + 1)); }); var v = counter.GetValue(); // Succeeds. this.Assert(v.Value1 == v.Value2); if (flag) { // Succeeds. this.Assert(v.Value1 == 2 || v.Value1 == 5 || v.Value1 == 6); } else { // Fails. this.Assert(v.Value1 == 2 || v.Value1 == 6); } }
protected override void OnLinkedTo(RuntimeHost runtimeHost, params object[] args) { if (args == null || args.Length == 0) { m_reg = SharedRegister.Create <T>(runtimeHost.Runtime); } else if (args.Length == 1 && args[0] is T value) { m_reg = SharedRegister.Create <T>(runtimeHost.Runtime, value); } else { throw new ArgumentOutOfRangeException(nameof(args), "The value needs to translate in null, empty or the array that has just one element as T."); } }
public void TestProductionSharedRegister() { var runtime = PSharpRuntime.Create(); var counter = SharedRegister.Create <int>(runtime, 0); counter.SetValue(5); var tcs1 = new TaskCompletionSource <bool>(); var tcs2 = new TaskCompletionSource <bool>(); var failed = false; runtime.OnFailure += delegate { failed = true; tcs1.SetResult(true); tcs2.SetResult(true); }; var m1 = runtime.CreateMachine(typeof(M), new E(counter, tcs1)); var m2 = runtime.CreateMachine(typeof(M), new E(counter, tcs2)); Task.WaitAll(tcs1.Task, tcs2.Task); Assert.False(failed); }
public E(SharedRegister <T> counter) { this.Counter = counter; }
public E(SharedRegister <int> counter, TaskCompletionSource <bool> tcs) { this.Counter = counter; this.Tcs = tcs; }