Garbage collecting computations

Imagine a process starting two computations, and as soon as one of them returns, abandoning the other.

One way to implement this is to require the client process to explicitly request cancellation of the second computation. I see this as similar to manual management of memory, with all the benefits and drawbacks.

Another way is to use something similar to garbage collector - the client just forgets about the second computation, and it will be (eventually) cancelled. I like to think about this as a GC because (as with memory GC) there are no semantic guarantees, just a pragmatic one - the infrastructure will have an option to reduce the consumption of resources, but does not guarantee it will use it (e.g., the resources are in abundance - a lot of free physical memory or idle processors).

Similar to memory GC, there might be ways for the process to detect the infrastructure's decision - in case of memory by means of finalizer code being called, in case of computation by detecting the effects of the computation.

What is not so similar, is the nature of references. In case of memory, clients refer to memory blocks. In case of computations, the direction is reversed - the computation refers to the continuation supplied by the client. That looks like a fatal blow...

I vaguely remember reading about something like that in the context of speculative computations, but was unable to find it again. Any ideas where to look?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

try this

A pointer

Wadler suggested fixing some space leaks in implementations of lazy languages by letting the garbage collector do a small amount of work.
Fixing some space leaks with a garbage collector

This trick was later generalized by Christina von Dorrien who called it "Stingy Evaluation".

Thanks!

Yes, that's it. Futures. I knew it is a well-known concept. Now I have to go and check, if they fit my language... I already have continuations, and I actually hoped to get away without introducing any other constructs at the base level... Let's see if it's possible.

Subcontinuations

I suspect that my specific problem can be solved by spawn of Subcontinuations fame.

Yet another investigation of interplay between futures and continuations: Continuing into the Future: the Return (I am affraid the original paper is kept under ACM digital press).