I would like to run a test against C# (I want to compare it’s run speed to another language).
What I would like to do is create 100,000 threads in a chain, have each wait for a value from the thread before it, when it gets the value add 1 and pass the value to the next thread.
The idea is to see how quickly it can create those threads and add up to 100,000.
I have no idea how to write that code. I can do pieces of it like threading and timing, but I’m not sure how to string them together.
EDIT
It seems I also get to learn about my deficiencies in knowledge when it comes to Threading. So let’s assume that Thread Pooling (or some other low level method) is comparable, can anyone show me examples of that?
This scenario is exactly what the TPL is designed to achieve, in particular
ContinueWith, orawaitin C# 5 parlance. Note that async != threading (although they are related), but the point is that you are actually trying to execute 100k tasks, not 100k threads. These two concepts are different. The TPL is the right way to do this. Always use an appropriate tool for the job.I’ll happily whip up a TPL example if you want… something not too far to: