Next: , Previous: , Up: iklib   [Index]


6.9 The unwind–protection mechanism

Unwind–protection allows operations to be performed synchronously with respect to the dynamic extent of a call to thunk; the mechanism is sophisticated because there are multiple, sophisticated ways to exit the dynamic extent of a function call. The typical application is to release resources, like input/output ports and database connections. Allocating and releasing resources, for an overview of resource management under Vicare.

To understand the unwind–protection mechanism we must understand the concepts “dynamic extent of a function call” and “dynamic environment” ad defined by R6RS (see scheme basic dynamic extent). Notes on the dynamic environment.

The unwind–protection mechanism described here is used by Vicare in: the implementation of compensations (see iklib compensations); the implementation of the syntax try (see iklib syntaxes try); the implementation of condition handlers and restarts ((vicare-libs)Signalling conditions and restarts).

NOTE The unwind protection mechanism may misbehave in some cases, so do not trust it blindly (see iklib unwind-protect problems).


Next: , Previous: , Up: iklib   [Index]