Concepts+Techniques+and+Models+of+Computer+Programming_Part12

Concepts+Techniques+and+Models+of+Computer+Programming_Part12

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 288 Declarative Concurrency Memory management There are two modifications to memory management: • Extending the definition of reachability: A variable x is reachable if the trigger store contains trig ( x, y ) and y is reachable. • Reclaiming triggers: If a variable y becomes unreachable and the trigger store contains trig ( x, y ), then remove the trigger. Needing a variable What does it mean for a variable to be needed? The definition of need is carefully designed so that lazy execution is declarative, i.e., all executions lead to logically- equivalent stores. A variable is needed by a suspended operation if the variable must be determined for the operation to continue. Here is an example: thread X={ByNeed fun {$} 3 end } end thread Y={ByNeed fun {$} 4 end } end thread Z=X+Y end To keep the example simple, let us consider that each thread executes atomically. This means there are six possible executions. For lazy execution to be declarative, all of these executions must lead to equivalent stores. Is this true? Yes, it is true, because the addition will wait until the other two triggers are created, and these triggers will then be activated. There is a second way a variable can be needed. A variable is needed if it is determined. If this were not true, then the demand-driven concurrent model would not be declarative. Here is an example: thread X={ByNeed fun {$} 3 end } end thread X=2 end thread Z=X+4 end The correct behavior is that all executions should fail. If X=2 executes last then the trigger has already been activated, binding X to 3, so this is clear. But if X=2 is executed first then the trigger should also be activated. Let us conclude by giving a more subtle example: thread X={ByNeed fun {$} 3 end } end thread X=Y end thread if X==Y then Z=10 end end Should the comparison X==Y activate the trigger on X ? According to our definition the answer is no . If X is made determined then the comparison will still not execute (since Y is unbound). It is only later on, if Y is made determined, that the trigger on X should be activated. Being needed is a monotonic property of a variable. Once a variable is needed, it stays needed forever. Figure 4.25 shows the stages in a variable’s lifetime. Note that a determined variable is always needed, just by the fact of being determined. Monotonicity of the need property is essential to prove that the demand-driven concurrent model is declarative. Copyright c 2001-3 by P. Van Roy and S. Haridi. All rights reserved. 4.5 Lazy execution 289 Unbound needed + Determined needed + Unbound Figure 4.25: Stages in a variable’s lifetime Using by-need triggers By-need triggers can be used to implement other concepts that have some “lazy” or “demand-driven” behavior. For example, they underlie lazy functions and dynamic linking. Let us examine each in turn....
View Full Document

Page1 / 30

Concepts+Techniques+and+Models+of+Computer+Programming_Part12

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online