static void RaceConditions() { var state = new StateObject(); for (int i = 0; i < 2; i++) { Task.Run(() => new SampleTask().RaceCondition(state)); } }
static void RaceConditions() { var state = new StateObject(); for (int i = 0; i < 2; i++) { new Task(new SampleTask().RaceCondition, state).Start(); } }
static void Deadlock() { var s1 = new StateObject(); var s2 = new StateObject(); Task.Run(() => new SampleTask(s1, s2).Deadlock1()); Task.Run(() => new SampleTask(s1, s2).Deadlock2()); Thread.Sleep(100000); }
static void Deadlock() { var s1 = new StateObject(); var s2 = new StateObject(); new Task(new SampleTask(s1, s2).Deadlock1).Start(); new Task(new SampleTask(s1, s2).Deadlock2).Start(); Thread.Sleep(10); }
public SampleTask(StateObject s1, StateObject s2) { this.s1 = s1; this.s2 = s2; }