Answer the question
In order to leave comments, you need to log in
ASP.NET multithreading question - how do blocked threads work?
There is an asp.net mvc application (not core), hosted in openwork. There is one single core.
How I imagine the logic of work:
For each incoming request, a thread is created. There may or may not be asynchrony inside a thread. Each thread gets a time slice and all threads work in turn until they are done.
The question is the following: if we have a blocking operation in one thread (for example, we synchronously climbed into the database), then how will this thread affect the work of other threads?
Will it receive its time slices, the same as other threads?
If yes (it will receive so much) - will starting calls to the database through async / await help?
If not, then why async/await at all, if the thread stops without them?
Or am I in some place fundamentally mistaken?
Answer the question
In order to leave comments, you need to log in
ASP.NET MVC and Web API - Comparison of Async / Sy...
There is a thread pool.
A request came - they got a thread from the pool, and it began to process the request.
If a thread met an await (a request to the database, for example, not a CPU bound operation) and the result is not available (may be available immediately), then it went back to the pool. When await receives a result, a thread will be taken from the pool and the result will be passed to it, and it will continue execution.
If a thread encounters a request in the database, but there is no await, then it will remain waiting for the result, it will not return to the pool, it will not be able to serve other requests, it will just wait.
Real life example:
We ordered pizza by phone.
- synchronously - we go to the door and wait for a call from the courier.
- asynchronously - doing other things, when the courier delivers the pizza, he will ring the doorbell and we will come for her.
Asynchrony != multithreading, that's part of it.
What is the difference between asynchronous program...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question