Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "naturally asynchronous" or "pure asynchronous"?

In a lot of discussions about C#'s async/await, I see people mention the term "naturally asynchronous" or "pure asynchronous". What exactly do these terms mean?

What are some examples of a "naturally asynchronous" operation and why is it called so?

What are some examples of a "non-naturally asynchronous" operation, and why?

like image 397
Chin Avatar asked Jul 30 '15 20:07

Chin


People also ask

What makes something asynchronous?

Asynchronous in computer programming In computer programming, asynchronous operation means that a process operates independently of other processes, whereas synchronous operation means that the process runs only as a result of some other process being completed or handed off.

What is the meaning of BeginInvoke and EndInvoke method?

BeginInvoke returns an IAsyncResult, which can be used to monitor the progress of the asynchronous call. The EndInvoke method retrieves the results of the asynchronous call. It can be called any time after BeginInvoke . If the asynchronous call has not completed, EndInvoke blocks the calling thread until it completes.

What is asynchronous programming example?

Asynchronous programming can help systems run more effectively, depending on the situation and often prevents long wait times. For example, if a task you want to perform uses a lot of input and output, asynchronous programming lets other tasks run, whereas synchronous programming would create a time block.

What asynchronous used for?

Asynchronous functions are often found in front end applications and used particularly in independent, high volume, IO tasks. Front end applications benefit from its use because it enhances the flow of an application. Backend processes may use asynchronous functions to run many tasks or make lots of network calls.


1 Answers

It's almost always I/O.

Naturally asynchronous operations are operations that don't require the CPU, like sending data over the network or reading data from the hard drive. They don't require any computations so the CPU can do other tasks while they run.

There are also logical operations that don't require a thread, for example waiting for a timeout to expire, or wait on synchronization constructs (e.g. AsyncLock)

Operations that are asynchronous but not naturally asynchronous are CPU operations being executed on a background thread. These are useful for responsiveness (e.g. For UI apps) but don't improve performance or scalability as they still require the same amount of resources.

So you have:

Naturally asynchronous operations running asynchronously:

await Task.Delay(1000);

Naturally asynchronous operations running synchronously:

Thread.Sleep(1000);

Naturally synchronous operations running asynchronously:

await Task.Run(() => CalculateSquareRoot(5));

Naturally synchronous operations running synchronously:

CalculateSquareRoot(5);
like image 176
i3arnon Avatar answered Nov 15 '22 18:11

i3arnon