3

I've been reading (and working) quite a bit with massively multi-threaded applications, and with IO, and I've found that the term asynchronous has become some sort of catch-all for multiple vague ideas. I'm wondering if I understand it correctly. The way I see it is that there are two main branches of "asynchronicity".

  1. Asynchronous I/O. Such as network read/write. What this really boils down to is efficient parallel processing between multiple CPUs, such as your main CPU and your NIC CPU. The idea is to have multiple processors running in parallel, exchanging data, without blocking waiting for the other to finish and return the results of it's job.
  2. Minimizing context-switching penalties by minimizing use of threads. This seems to be what the .NET framework is focusing on with it's async/await features. Instead of spawning/closing/blocking threads, break parallel jobs into tasks, and use a software task scheduler to keep a pool of threads as busy as possible without resorting to spawning new threads.

These seem like two entirely separate concepts with no similarities that could tie them together, but are both referred to by the same "asynchronous computing" vocabulary.

Am I understanding all of this correctly?

3 Answers 3

5

Asynchronous basically means not blocking, i.e. not having to wait for an operation to complete.

Threads are just one way of accomplishing that. There are many ways of doing this, from hardware level, SO level, software level.

Someone with more experience than me can give examples of asyncronicity not related to threads.

Sign up to request clarification or add additional context in comments.

Comments

3

Asynchronous is a general term, which does not have widely accepted meaning. Different domains have different meanings to it.

For instance, async IO means that instead of blocking on IO call, something else happens. Something else can be really different things, but it usually involves some sort of notification of call completion. Details might differ. For instance, a notification might be built into the call itself - like in MS Completeion Ports (if memory serves). Or, it can be something verify do before you make a call so that the call can not block - this is what poll() and friends do.

Async might also well mean simply parallel execution. For instance, one might say that 'database is updated asynchronously' meaning that there is a dedicated thread which handles database connectivity, and that thread does not slow down the main processing thread.

Comments

1

What this really boils down to is efficient parallel processing between multiple CPUs, such as your main CPU and your NIC CPU. The idea is to have multiple processors running in parallel...

Asynchronous programming is not all about multi-core CPU's and parallelism: consider a single core CPU, with just one thread creating email messages and sends them. In a synchronous fashion, it would spend a few micro seconds to create the message, and a lot more time to send it through network, and only then create the next message. But in asynchronous program, the thread could create a new message while the previous one is being sent through the network. One implementation for that kind of program can be using .NET async/await feature, where you can have just one thread. But even a blocking IO program could be considered asynchronous: If the main thread creates the messages and queues them in a buffer, which another thread pulls them from and sends them in a blocking IO way. From the main thread's point of view - it's completely async.

.NET async/await just uses the OS api's which are already async - reading /writing a file, send /receive data through network, they are all async anyway - the OS doesn't block on them (the drivers themselves are async).

3 Comments

"it would spend a few micro seconds to create the message, and a lot more time to send it through network, and only then create the next message."... But what it's really waiting for is for the NIC processor to send some return signal indicating that the network process is finished. The same with file I/O, it's waiting for your disk controller to report that the operation is finished. So at the low level it's still about multiple processors working together efficiently.
This is just a matter of semantics - how would you describe the asynchronous operation of Task.Delay(int) in .NET? At the low level is just signal from the counter, and I suppose you wouldn't consider it as "multiple processors working together" :)
That would be explained by my second definition of asynchronicity. The only difference between Task.Delay(int) and Thread.Sleep(int) is that Delay() does not block a thread. The thread is returned to the pool to be scheduled a different task. The overall goal being minimizing the number of threads running, and thus minimizing thread overhead. Such as private stack size and context-switching penalties. This and efficient multi-processor computing are very different things, which is why it bothers me that they're grouped under the same "asynchronous" umbrella.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.