Jump to content

Asynchronous procedure call

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Akaigoro (talk | contribs) at 12:38, 6 April 2018 (General description of Asynchronous procedure call started.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Asynchronous procedure call is a unit of work in a computer. Usually program works 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 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 lifecycle 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 call 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 one port to receive input data, while Actor Dataflow programming can have many, and goes to execution service when all inputs contain data.

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

References

  1. ^ a b "Asynchronous Procedure Calls (Windows)". Retrieved 1 March 2017.