Created
December 14, 2022 16:14
-
-
Save AntonSmolkov/e2df02aa4e556be2a397788d0115f647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Concurrent; | |
using System.Diagnostics; | |
using System.Threading.Channels; | |
var lockObject = new object(); | |
var blockingCollection = new BlockingCollection<int>(10); | |
var channel = Channel.CreateBounded<int>(new BoundedChannelOptions(10) {SingleReader = true}); | |
var cts = new CancellationTokenSource(); | |
cts.CancelAfter(30000); | |
while (!cts.IsCancellationRequested) | |
{ | |
Task.Run(() => | |
{ | |
//blockingCollection.Add(0); //Result - 52 threads | |
//channel.Writer.WriteAsync(0).AsTask().GetAwaiter().GetResult(); // Result - 147 threads | |
//lock (lockObject) { channel.Writer.WriteAsync(0).AsTask().GetAwaiter().GetResult(); } //Result - 56 threads | |
//var j = 1 + 1; // Result - 15 threads | |
}); | |
Console.WriteLine(Process.GetCurrentProcess().Threads.Count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment