←back to thread

305 points kristoff_it | 1 comments | | HN request time: 0s | source
Show context
kazinator ◴[] No.44610332[source]
Asynchrony, in this context, is an abstraction which separates the preparation and submission of a request from the collection of the result.

The abstraction makes it possible to submit multiple requests and only then begin to inquire about their results.

The abstraction allows for, but does not require, a concurrent implementation.

However, the intent behind the abstraction is that there be concurrency. The motivation is to obtain certain benefits which will not be realized without concurrency.

Some asynchronous abstractions cannot be implemented without some concurrency. Suppose the manner by which the requestor is informed about the completion of a request is not a blocking request on a completion queue, but a callback.

Now, yes, a callback can be issued in the context of the requesting thread, so everything is single-threaded. But if the requesting thread holds a non-recursive mutex, that ruse will reveal itself by causing a deadlock.

In other words, we can have an asynchronous request abstraction that positively will not work single threaded;

1 caller locks a mutex

2 caller submits request

3 caller unlocks mutex

4 completion callback occurs

If step 2 generates a callback in the same thread, then step 3 is never reached.

The implementation must use some minimal concurrency so that it has a thread waiting for 3 while allowing the requestor to reach that step.

replies(1): >>44613227 #
brabel ◴[] No.44613227[source]
Completely agree. The server/client example in the post was just one example of a program not being able to make progress, you’ve just gave another which cannot be solved the same way, and I would bet there are many more that they will be discovering over time. IMO when async is used, concurrency needs to be ensured.
replies(1): >>44615213 #
1. kazinator ◴[] No.44615213[source]
It depends on the API. If the only way to obtain the result of the asynchronous dispatch is a synchronous operation on a completion queue, then there are no cases where a single-threaded implementation will break, other than not providing the performance.

However, we can argue that if there is only a synchronous operation to collect the result, then it's not truly async. Asynchrony should mean not only that we can initiate a request without waiting for the result, but that the completion can happen at any time.