Futures and promises

A Future (English, Future ') or a Promise ( engl. ' promise ' ) referred to in programming a wildcard ( proxy ) for a result that is not known yet, mostly because its calculation is not yet complete.

A future is most often the result of an asynchronous call to a function or method and can be used to access the result as soon as it is available. This type of programming allows a largely transparent parallelization of concurrent processes. The concept of futures was presented in an article by Henry G. Baker and Carl Hewitt 1977.

A central idea of programming with futures is that futures can be passed as arguments to other procedure calls. The evaluation of this call can begin then, before the result of the futures is even available. That allows a maximum degree of parallelism. If the new call in turn asynchronously, so it is also called pipelining the futures. Pipelining can be used especially in distributed applications in order to minimize the latency of inter-process communication.

Function

Futures are a construct for asynchronous inter-process communication. This concept offers a future or a get- join function that blocks until the result is available, and this then returns. Depending on the implementation, the waiting time by timeout can be restricted or by additional functions to query the current status.

Are futures integrated directly in the programming language, so only an asynchronous assignment operator is often defined, for example, @ x = expression in Flow Java, a style similar to Java experimental programming language. This means: start a process for calculating the expression that is to the right of the operator, and the variable x as a Future for the result to. If x then access the variable, so wait at this point until the result is available.

Support programming languages ​​and libraries which futures or Promises are CORBA ( with Asynchronous Method Invocation ( AMI) ), io, Oz, Scheme, Smalltalk, and - since version 5 - Java Concurrency Utilities means, a class library for concurrency. Also for C are different libraries, the most famous of them is probably boost. In the new Standard C 11 concurrency and futures are also available in the standard library.

In C # 5.0 and Visual Basic 2013 futures are used for async and await implicitly. A corresponding future class is defined here in the parallel extensions and can be used in earlier versions, and other programming languages. Such may also be implemented even if required, however.

Construction

A future is a monad with an associated resolver, which assigns a value to the Future. The Future may be in one of three states:

  • Satisfies (English: promise kept )
  • Broken (English: promise broken )
  • Waiting (English: promise pending)

If the value so assigned by the resolver and known to the Future generates an event for which callback functions can be registered.

Example

The following pseudo code shows the use of futures by means of the asynchronous assignment operator @ =.

Var x = @ berechneX (); / / Start computation of x var y = @ berechneY (); / / Start computation of y var z = berechneZ (); / / Complete calculation of z var result = x y z; / / Use x, y and z                             / / Here, then, it may be necessary to calculate                             / / Wait to be x and y. This yields the following parallelization:

The breakdown of the calculation on multiple threads can speed up calculations significantly when multiple CPUs (or cores ) are available, or if the individual calculations do not utilize the main processor because they spend some much time waiting on peripherals.

357424
de