Concurrently cached values.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Pure/Concurrent/cache.ML Thu Oct 01 22:39:06 2009 +0200
@@ -0,0 +1,32 @@
+(* Title: Pure/Concurrent/cache.ML
+ Author: Makarius
+
+Concurrently cached values, with minimal locking time and singleton
+evaluation due to lazy storage.
+*)
+
+signature CACHE =
+sig
+ val create: 'table -> ('table -> 'key -> 'value lazy option) ->
+ ('key * 'value lazy -> 'table -> 'table) -> ('key -> 'value) -> 'key -> 'value
+end;
+
+structure Cache: CACHE =
+struct
+
+fun create empty lookup update f =
+ let
+ val cache = Synchronized.var "cache" empty;
+ fun apply x =
+ Synchronized.change_result cache
+ (fn tab =>
+ (case lookup tab x of
+ SOME y => (y, tab)
+ | NONE =>
+ let val y = Lazy.lazy (fn () => f x)
+ in (y, update (x, y) tab) end))
+ |> Lazy.force;
+ in apply end;
+
+end;
+
--- a/src/Pure/IsaMakefile Thu Oct 01 20:47:26 2009 +0200
+++ b/src/Pure/IsaMakefile Thu Oct 01 22:39:06 2009 +0200
@@ -42,37 +42,37 @@
Pure: $(OUT)/Pure
-$(OUT)/Pure: $(BOOTSTRAP_FILES) Concurrent/future.ML \
- Concurrent/lazy.ML Concurrent/lazy_sequential.ML \
- Concurrent/mailbox.ML Concurrent/par_list.ML \
- Concurrent/par_list_sequential.ML Concurrent/simple_thread.ML \
- Concurrent/synchronized.ML Concurrent/synchronized_sequential.ML \
- Concurrent/task_queue.ML General/alist.ML General/antiquote.ML \
- General/balanced_tree.ML General/basics.ML General/binding.ML \
- General/buffer.ML General/file.ML General/graph.ML General/heap.ML \
- General/integer.ML General/long_name.ML General/markup.ML \
- General/name_space.ML General/ord_list.ML General/output.ML \
- General/path.ML General/position.ML General/pretty.ML \
- General/print_mode.ML General/properties.ML General/queue.ML \
- General/same.ML General/scan.ML General/secure.ML General/seq.ML \
- General/source.ML General/stack.ML General/symbol.ML \
- General/symbol_pos.ML General/table.ML General/url.ML General/xml.ML \
- General/yxml.ML Isar/args.ML Isar/attrib.ML Isar/auto_bind.ML \
- Isar/calculation.ML Isar/class.ML Isar/class_target.ML Isar/code.ML \
- Isar/constdefs.ML Isar/context_rules.ML Isar/element.ML \
- Isar/expression.ML Isar/isar_cmd.ML Isar/isar_document.ML \
- Isar/isar_syn.ML Isar/local_defs.ML Isar/local_syntax.ML \
- Isar/local_theory.ML Isar/locale.ML Isar/method.ML \
- Isar/object_logic.ML Isar/obtain.ML Isar/outer_keyword.ML \
- Isar/outer_lex.ML Isar/outer_parse.ML Isar/outer_syntax.ML \
- Isar/overloading.ML Isar/proof.ML Isar/proof_context.ML \
- Isar/proof_display.ML Isar/proof_node.ML Isar/rule_cases.ML \
- Isar/rule_insts.ML Isar/runtime.ML Isar/skip_proof.ML \
- Isar/spec_parse.ML Isar/specification.ML Isar/theory_target.ML \
- Isar/toplevel.ML Isar/value_parse.ML ML/ml_antiquote.ML \
- ML/ml_compiler.ML ML/ml_compiler_polyml-5.3.ML ML/ml_context.ML \
- ML/ml_env.ML ML/ml_lex.ML ML/ml_parse.ML ML/ml_syntax.ML \
- ML/ml_thms.ML ML-Systems/install_pp_polyml.ML \
+$(OUT)/Pure: $(BOOTSTRAP_FILES) Concurrent/cache.ML \
+ Concurrent/future.ML Concurrent/lazy.ML \
+ Concurrent/lazy_sequential.ML Concurrent/mailbox.ML \
+ Concurrent/par_list.ML Concurrent/par_list_sequential.ML \
+ Concurrent/simple_thread.ML Concurrent/synchronized.ML \
+ Concurrent/synchronized_sequential.ML Concurrent/task_queue.ML \
+ General/alist.ML General/antiquote.ML General/balanced_tree.ML \
+ General/basics.ML General/binding.ML General/buffer.ML \
+ General/file.ML General/graph.ML General/heap.ML General/integer.ML \
+ General/long_name.ML General/markup.ML General/name_space.ML \
+ General/ord_list.ML General/output.ML General/path.ML \
+ General/position.ML General/pretty.ML General/print_mode.ML \
+ General/properties.ML General/queue.ML General/same.ML \
+ General/scan.ML General/secure.ML General/seq.ML General/source.ML \
+ General/stack.ML General/symbol.ML General/symbol_pos.ML \
+ General/table.ML General/url.ML General/xml.ML General/yxml.ML \
+ Isar/args.ML Isar/attrib.ML Isar/auto_bind.ML Isar/calculation.ML \
+ Isar/class.ML Isar/class_target.ML Isar/code.ML Isar/constdefs.ML \
+ Isar/context_rules.ML Isar/element.ML Isar/expression.ML \
+ Isar/isar_cmd.ML Isar/isar_document.ML Isar/isar_syn.ML \
+ Isar/local_defs.ML Isar/local_syntax.ML Isar/local_theory.ML \
+ Isar/locale.ML Isar/method.ML Isar/object_logic.ML Isar/obtain.ML \
+ Isar/outer_keyword.ML Isar/outer_lex.ML Isar/outer_parse.ML \
+ Isar/outer_syntax.ML Isar/overloading.ML Isar/proof.ML \
+ Isar/proof_context.ML Isar/proof_display.ML Isar/proof_node.ML \
+ Isar/rule_cases.ML Isar/rule_insts.ML Isar/runtime.ML \
+ Isar/skip_proof.ML Isar/spec_parse.ML Isar/specification.ML \
+ Isar/theory_target.ML Isar/toplevel.ML Isar/value_parse.ML \
+ ML/ml_antiquote.ML ML/ml_compiler.ML ML/ml_compiler_polyml-5.3.ML \
+ ML/ml_context.ML ML/ml_env.ML ML/ml_lex.ML ML/ml_parse.ML \
+ ML/ml_syntax.ML ML/ml_thms.ML ML-Systems/install_pp_polyml.ML \
ML-Systems/install_pp_polyml-5.3.ML ML-Systems/use_context.ML \
Proof/extraction.ML Proof/proof_rewrite_rules.ML \
Proof/proof_syntax.ML Proof/proofchecker.ML Proof/reconstruct.ML \
--- a/src/Pure/ROOT.ML Thu Oct 01 20:47:26 2009 +0200
+++ b/src/Pure/ROOT.ML Thu Oct 01 22:39:06 2009 +0200
@@ -56,19 +56,25 @@
(* concurrency within the ML runtime *)
use "Concurrent/simple_thread.ML";
+
use "Concurrent/synchronized.ML";
if Multithreading.available then ()
else use "Concurrent/synchronized_sequential.ML";
+
use "Concurrent/mailbox.ML";
use "Concurrent/task_queue.ML";
use "Concurrent/future.ML";
+
use "Concurrent/lazy.ML";
if Multithreading.available then ()
else use "Concurrent/lazy_sequential.ML";
+
use "Concurrent/par_list.ML";
if Multithreading.available then ()
else use "Concurrent/par_list_sequential.ML";
+use "Concurrent/cache.ML";
+
(* fundamental structures *)