// This is a separate method for target=DEBUG purposes. // In release builds, the runtime is smart enough to figure out // that the contexts are unreachable and should be collected but in // debug builds... well, it's not very smart. object LeaksCollectedAndRePooled_Initialize(ConnectionMultiplexer conn, int threadCount) { var profiler = new TestProfiler3(); conn.RegisterProfiler(profiler); var perThreadContexts = new List <object>(); for (var i = 0; i < threadCount; i++) { perThreadContexts.Add(new object()); } var threads = new List <Thread>(); var results = new IEnumerable <IProfiledCommand> [threadCount]; for (var i = 0; i < threadCount; i++) { var ix = i; var thread = new Thread( delegate() { var ctx = perThreadContexts[ix]; profiler.RegisterContext(ctx); conn.BeginProfiling(ctx); var db = conn.GetDatabase(ix); var allTasks = new List <Task>(); for (var j = 0; j < 1000; j++) { allTasks.Add(db.StringGetAsync("hello" + ix)); allTasks.Add(db.StringSetAsync("hello" + ix, "world" + ix)); } Task.WaitAll(allTasks.ToArray()); // intentionally leaking! } ); threads.Add(thread); } threads.ForEach(t => t.Start()); threads.ForEach(t => t.Join()); var anyContext = profiler.AnyContext(); profiler.Reset(); return(anyContext); }
// This is a separate method for target=DEBUG purposes. // In release builds, the runtime is smart enough to figure out // that the contexts are unreachable and should be collected but in // debug builds... well, it's not very smart. object LeaksCollectedAndRePooled_Initialize(ConnectionMultiplexer conn, int threadCount) { var profiler = new TestProfiler3(); conn.RegisterProfiler(profiler); var perThreadContexts = new List<object>(); for (var i = 0; i < threadCount; i++) { perThreadContexts.Add(new object()); } var threads = new List<Thread>(); var results = new IEnumerable<IProfiledCommand>[threadCount]; for (var i = 0; i < threadCount; i++) { var ix = i; var thread = new Thread( delegate() { var ctx = perThreadContexts[ix]; profiler.RegisterContext(ctx); conn.BeginProfiling(ctx); var db = conn.GetDatabase(ix); var allTasks = new List<Task>(); for (var j = 0; j < 1000; j++) { allTasks.Add(db.StringGetAsync("hello" + ix)); allTasks.Add(db.StringSetAsync("hello" + ix, "world" + ix)); } Task.WaitAll(allTasks.ToArray()); // intentionally leaking! } ); threads.Add(thread); } threads.ForEach(t => t.Start()); threads.ForEach(t => t.Join()); var anyContext = profiler.AnyContext(); profiler.Reset(); return anyContext; }