Asynchronous procedure call
Asynchronous procedure call is a unit of work in a computer. Usually a program works by executing a series of synchronous procedure calls on some thread. But if some data are not ready (for example, a program waits user to reply), then keeping thread in wait state is impractical, as a thread allocates considerable amount of memory for procedure stack, and this memory is not used. So such a procedure call is formed as an object with small amount of memory for input data, and this object is passed to the service which receive user inputs. When the user's reply is received, the service puts it in the object and passes that object to an execution service. Execution service consists of one or more dedicated worker threads and a queue for tasks. Each worker thread reads in a loop task queue and, when a task is retrieved, executes it. When there is no tasks, worker threads are waiting and so their memory is not used, but the number of worker threads is small enough (no sense to have more threads than there are processors on the machine).
So life cycle of an asynchronous procedure call consists of 2 stages: passive stage, when it passively waits or input data, and active state, when that data are calculated in the same way as at usual procedure call.
The object of the asynchronous procedure call can be reused for subsequent procedure calls with new data, received later. This allows to accumulate computed output data in that object, as it is usually done in objects, programmed with Object-oriented programming paradigm. Special care should be paid to avoid simultaneous execution of the same procedure call in order to keep computed data in consistent state. Such reusable asynchronous procedure is named Actor. Programming using Actors is described in Actor model and Dataflow programming. The difference is that Actor in the Actor model has exactly two ports: one port to receive input data, and another (hidden) port to provide serial handling of input messages, while Actor in Dataflow programming can have many, and goes to execution service when all inputs contain data or permissions.
Some specific implementations
In Windows, an asynchronous procedure call (abbreviated 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).
- "Asynchronous Procedure Calls (Windows)". Retrieved 1 March 2017.