Asynchronous procedure call

An asynchronous procedure call (APC) is a unit of work in a computer.

Definition
Procedure calls can be synchronous or asynchronous. Synchronous procedure calls are made on one thread in a series, with each call waiting for the prior call to complete. on some thread. APCs instead are made without waiting for prior calls to complete.

For example, if some data are not ready (for example, a program waits for a user to reply), then stopping other activity on the thread is expensive, the thread has consumed memory and potentially other resources.

Structure
An APC is typically formed as an object with a small amount of memory and this object is passed to a service which handles the wait interval, activating it when the appropriate event (e.g., user input) occurs.

The life cycle of an APC consists of 2 stages: the passive stage, when it passively waits for input data, and active state, when that data is calculated in the same way as at the usual procedure call.

A reusable asynchronous procedure is termed Actor. In the Actor model two ports are used: one to receive input, and another (hidden) port to handle the input. In Dataflow programming many ports are used, passing to an execution service when all inputs are present.

Implementations
In Windows, APC is a function that executes asynchronously in the context of a specific thread. APCs can be generated by the system (kernel-mode APCs) or by an application (user mode APCs).