avoid resource problems of JVM by too many parallel XZ compression tasks;
authorwenzelm
Wed, 17 Jun 2020 19:46:50 +0200
changeset 71939 107472ccc60d
parent 71938 e1b262e7480c
child 71940 026de3424c39
avoid resource problems of JVM by too many parallel XZ compression tasks;
src/Pure/Thy/export.scala
--- a/src/Pure/Thy/export.scala	Tue Jun 16 08:41:39 2020 +0000
+++ b/src/Pure/Thy/export.scala	Wed Jun 17 19:46:50 2020 +0200
@@ -143,11 +143,19 @@
       regex.pattern.matcher(compound_name(theory_name, name)).matches
   }
 
+  private lazy val later: Consumer_Thread[() => Unit] =
+    Consumer_Thread.fork(name = "Export.later", daemon = true)(
+      consume = (run: () => Unit) => { run(); true })
+
   def make_entry(session_name: String, args: Protocol.Export.Args, body: Bytes,
     cache: XZ.Cache = XZ.cache()): Entry =
   {
     Entry(session_name, args.theory_name, args.name, args.executable,
-      if (args.compress) Future.fork(body.maybe_compress(cache = cache))
+      if (args.compress) {
+        val result = Future.promise[(Boolean, Bytes)]
+        later.send(() => result.fulfill(body.maybe_compress(cache = cache)))
+        result
+      }
       else Future.value((false, body)))
   }