Sachin Singh

Sachin Singh

  • 7
  • 55.8k
  • 81.7k

Async and Await c#

Jun 23 2021 12:51 PM

I understand these things

1. Multi-threading is actually not parallel, because instead of utilizing the cores in parallel efficiently, they run on a single core and do time slicing, I have tested it using perfmon.

2. TPL does the work really in parallel and utilizes all the cores efficiently, yes I tested this too using perfmon.

3. Async just introduces a state machine and now the method actually becomes object and properties, yes i tested this using ILSpy.

4. Await frees the calling thread and acts as a checkpoint for the state machine that tells from where to resume the method when others get completed, again I tested this using ILSpy.

Now my question is,

for IO-bound tasks, it is ok that they don't need threads like network driver, GPU, FileStream for reading, etc. But for CPU bounded task, how the thread remains the same when we use async and await, how the thread pool assigns the same thread to do the work (awaited task) in the background? 


Answers (1)