Asynchronous callouts
When a platform function call is made in Smalltalk, all Smalltalk processes block until that call completes. Asynchronous callout is an extension to the standard platform function call protocol that allows developers to make a platform function call in a separate thread. By making the call in a separate thread, it ensures that only those processes waiting on the result of the platform function call block.
For example, if a socket receive call that blocks is made in Smalltalk, no Smalltalk processes run until the receive call completes. By using asynchronous callout, only those processes waiting on the return value of the receive operation block.
These are the ways a Smalltalk process makes asynchronous calls:
Standard asynchronous call
The Smalltalk process blocks until the call completes. This type of call is used when the process needs the return value and cannot proceed until it has been calculated.
Resource future call
The Smalltalk process receives a future and continues to run, polling the future for the result of the platform function call. This type of call is used when the process does not immediately need the return value and can continue executing. Additionally, more than one process may wait on the return value.
Static future call
The Smalltalk process receives a future and continues to run, polling the future for the result of the platform function call. A static future call differs from a resource future call in that the same thread can be used by more than one call. Some calls, such as those that get the last error, require several platform function calls to be made in the same thread.
The syntax for using asynchronous calls is similar to normal platform function calls. The system sets up the OS resources required to make the call, executes the call, and recovers the resources automatically.
With resource futures calls, the system manages the OS resources. The system sets up the OS resources required to make the call, executes the call, and recovers the resources automatically. Resource future calls can be used for single asynchronous calls only.
Static futures calls require the developers to manage resources themselves. The advantage of a static future call is that it can be used to make more than one platform function call in the same thread. The developer must explicitly allocate the resources for the future and return them when the future is no longer required.
Last modified date: 01/29/2015