Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between asynchronous calls and asynchronous io calls in .net

Using a delegate I can call any function asynchronously. From the documentation I understand this is done by queueing a workitem for the threadpool.

One can also do asynchronous calls to IO functions (like reading from sockets, files, webpages, etc). I think (but I'm not sure) this does NOT spawn a workitem in the threadpool. Only after the result is obtained (or an error), is the callback called from a new thread in the threadpool.

Is this assumption correct? Or is an asynchronous IO call, also under the covers just some thread which is spawned? An if this is the case, how can asynchronous calls be any better performant than spawning threads (using a threadpool) yourself and block?

also: how many asynchronous calls can one have being dealt with at any given time? In case of a threadpool being used, I guess as much as you like. But in case of IO asynchronous calls, is there a limit? And is so, how do you know what the limit is?

like image 854
Toad Avatar asked Mar 05 '10 08:03

Toad


People also ask

What is difference between synchronous and asynchronous call?

Asynchronous Writes. Synchronous API calls are blocking calls that do not return until either the change has been completed or there has been an error. For asynchronous calls, the response to the API call is returned immediately with a polling URL while the request continues to be processed.

What is asynchronous calls?

An asynchronous method call is a method used in . NET programming that returns to the caller immediately before the completion of its processing and without blocking the calling thread.

What is difference between thread and async await in C#?

Threads. Async methods are intended to be non-blocking operations. An await expression in an async method doesn't block the current thread while the awaited task is running. Instead, the expression signs up the rest of the method as a continuation and returns control to the caller of the async method.


1 Answers

Asynchronous IO is much more complicated thing than just using another thread from thread pool.

There are many different techniques inside OS, that support asynchronous IO:

1 Signaling a device kernel object

Not useful for performing multiple simultaneous I/O requests against a single device. Allows one thread to issue an I/O request and another thread to process it.

2 Signaling an event kernel object

Allows multiple simultaneous I/O requests against a single device. Allows one thread to issue an I/O request and another thread to process it.

3 Using alertable I/O

Allows multiple simultaneous I/O requests against a single device. The thread that issued an I/O request must also process it.

4 Using I/O completion ports

Allows multiple simultaneous I/O requests against a single device. Allows one thread to issue an I/O request and another thread to process it. This technique is highly scalable and has the most flexibility.

like image 64
Sergey Teplyakov Avatar answered Nov 11 '22 23:11

Sergey Teplyakov