From 870677cbb85d05688ba85deb9807fdef8bd94e19 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Mon, 18 Jun 2018 15:16:40 +0200
Subject: [PATCH] compile: Work around non-thread-safe module autoloading.

* guix/build/compile.scm <top level>: Set 'try-module-autoload' when
running on Guile < 2.2.4.
---
 guix/build/compile.scm | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/guix/build/compile.scm b/guix/build/compile.scm
index 7b6e31107cf..5a1363556a1 100644
--- a/guix/build/compile.scm
+++ b/guix/build/compile.scm
@@ -196,6 +196,20 @@ (define (build file)
       (unless (zero? total)
         (report-compilation #f total total)))))
 
+(eval-when (eval load)
+  (when (and (string=? "2" (major-version))
+             (or (string=? "0" (minor-version))
+                 (and (string=? (minor-version) "2")
+                      (< (string->number (micro-version)) 4))))
+    ;; Work around <https://bugs.gnu.org/31878> on Guile < 2.2.4.
+    ;; Serialize 'try-module-autoload' calls.
+    (set! (@ (guile) try-module-autoload)
+      (let ((mutex (make-mutex 'recursive))
+            (real  (@ (guile) try-module-autoload)))
+        (lambda* (module #:optional version)
+          (with-mutex mutex
+            (real module version)))))))
+
 ;;; Local Variables:
 ;;; eval: (put 'with-augmented-search-path 'scheme-indent-function 2)
 ;;; eval: (put 'with-target 'scheme-indent-function 1)
-- 
GitLab