PDC@UNL

Asynchronous Computing

Background

We've seen how parallel computing can speed up computation by splitting work among different processors. Parallel computing is not the only type of concurrent programming, there is also Asycnhronous Computing.

Asynchronicity

Software often needs to perform several tasks which do not need to be done sequentially. This is true for most graphical interfaces which allow users to interact with a program in multiple different ways. For example, word processors let you continue to type whether you manually save or auto-save the document. Video games let you to continue playing while new obstacles or enemies appear or disappear. You would become very frustrated if games froze frequently to redraw all the items and characters. Instead, these kinds of tasks can be performed asynchronously without blocking execution of other tasks.

Consider the sequential timeline again where tasks must fully complete before the next task starts:

Sequential Computing

Asynchronous computing enables tasks to "pause" or wait while another task takes over. For example, one task could pause execution while it waits for more data to be sent over a relatively slow network. While the task waits, it gives control (often referred to as yielding) to another task so that processor time is not wasted waiting for the network. This idea is depicted in the following diagram.

Asynchronous Computing

In this example, Task 1 executes for some time and then waits or is blocked while Task 2 executes for some other amount of time. Task 1 then takes over again and this trading back-and-forth continues until each task completes. Note that only one task executes at a time, but multiple tasks can execute asynchronously. This can provide a huge time savings.

If Task 1 had to wait for the result of Task 2, Task 1 would sit idle until it received that result. Even worse, other tasks would sit idle or be blocked until Task 1 completed. Blocked tasks can cause your computer to freeze up entirely and require rebooting.

Activities

To understand these concepts further, you will engage in several demonstrations.

1. User Interface Playground

Click the "Start Demonstration" button below. This demonstration shows the differences between a sequential task which blocks other tasks compared to an asynchronous task which does not.

  1. Interact with the Say Hello! button and the Action drop-down to see how they work.
  2. Click the Sequential Operation button which will perform an "expensive" sequential computation. While it is executing attempt to interact with the Say Hello! button and the Action drop down. You can rerun the sequential operation as many times as you need to observe the results.
  3. Now click the Asynchronous Operation button which will perform an asynchronous computation by connecting to a remote server. While that asynchronous task is executing, interact with the Say Hello! button and the Action drop-down menu.
  4. Answer the following questions:
    • What did you observe when interacting with the interface while the sequential operation was executing?
    • What did you observe when interacting with the interface while the asynchronous operation was executing?
    • What are the consequences of sequential vs asynchronous operations?
Start Demonstration