From: Olivier Dion <olivier.dion@polymtl.ca>
To: Olivier Dion via <gwl-devel@gnu.org>
Cc: Olivier Dion <olivier.dion@polymtl.ca>
Subject: [PATCH 2/2] gwl/ui: Protect format to currnt-error-port with mutex
Date: Tue, 14 Jun 2022 15:53:37 -0400 [thread overview]
Message-ID: <20220614195337.30570-2-olivier.dion@polymtl.ca> (raw)
In-Reply-To: <20220614195337.30570-1-olivier.dion@polymtl.ca>
When executing processes in parallel, outputs from threads can be mangled
together if the access is not exclusive.
---
gwl/ui.scm | 59 +++++++++++++++++++++++++++++-------------------------
1 file changed, 32 insertions(+), 27 deletions(-)
diff --git a/gwl/ui.scm b/gwl/ui.scm
index 35bd127..339649c 100644
--- a/gwl/ui.scm
+++ b/gwl/ui.scm
@@ -19,6 +19,7 @@
#:use-module (guix colors)
#:use-module (srfi srfi-26)
#:use-module (ice-9 format)
+ #:use-module (ice-9 threads)
#:export (G_
log-event
@@ -39,6 +40,8 @@
(define %debug-color (color BOLD MAGENTA))
(define %execute-color (color BOLD YELLOW))
+(define log-mutex (make-recursive-mutex))
+
(define* (print-diagnostic-prefix prefix #:optional location
#:key (colors (color)))
"Print PREFIX as a diagnostic line prefix."
@@ -56,36 +59,38 @@
(colorize-string prefix colors))
identity))
- (if (location? location)
- (format (current-error-port) "~a: ~a"
- (location-color (location->string location))
- (prefix-color prefix))
- (format (current-error-port) "~a"
- (prefix-color prefix))))
+ (with-mutex log-mutex
+ (if (location? location)
+ (format (current-error-port) "~a: ~a"
+ (location-color (location->string location))
+ (prefix-color prefix))
+ (format (current-error-port) "~a"
+ (prefix-color prefix)))))
(define (log-event type . message)
(define print?
(or (member 'all (%config 'log-events))
(member type (%config 'log-events))))
(when print?
- (case type
- ((error)
- (print-diagnostic-prefix (G_ "error: ") #:colors %error-color))
- ((info)
- (print-diagnostic-prefix (G_ "info: ") #:colors %info-color))
- ((execute)
- (print-diagnostic-prefix (G_ "run: ") #:colors %execute-color))
- ((cache)
- (print-diagnostic-prefix (G_ "cache: ") #:colors %debug-color))
- ((debug)
- (print-diagnostic-prefix (G_ "debug: ") #:colors %debug-color))
- ((process)
- (print-diagnostic-prefix (G_ "process: ") #:colors %execute-color))
- ((guix)
- (print-diagnostic-prefix (G_ "guix: ") #:colors %execute-color))
- (else #true))
- (force-output (current-error-port))
- (format (current-error-port) "~2,2f "
- (/ (get-internal-real-time)
- internal-time-units-per-second))
- (apply format (current-error-port) message)))
+ (with-mutex log-mutex
+ (case type
+ ((error)
+ (print-diagnostic-prefix (G_ "error: ") #:colors %error-color))
+ ((info)
+ (print-diagnostic-prefix (G_ "info: ") #:colors %info-color))
+ ((execute)
+ (print-diagnostic-prefix (G_ "run: ") #:colors %execute-color))
+ ((cache)
+ (print-diagnostic-prefix (G_ "cache: ") #:colors %debug-color))
+ ((debug)
+ (print-diagnostic-prefix (G_ "debug: ") #:colors %debug-color))
+ ((process)
+ (print-diagnostic-prefix (G_ "process: ") #:colors %execute-color))
+ ((guix)
+ (print-diagnostic-prefix (G_ "guix: ") #:colors %execute-color))
+ (else #true))
+ (force-output (current-error-port))
+ (format (current-error-port) "~2,2f "
+ (/ (get-internal-real-time)
+ internal-time-units-per-second))
+ (apply format (current-error-port) message))))
--
2.36.1
next prev parent reply other threads:[~2022-06-14 19:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-10 0:56 auto-connect fails to parallelize independent processes Olivier Dion via
2022-06-10 13:13 ` Ricardo Wurmus
2022-06-13 20:02 ` Olivier Dion via
2022-06-14 19:04 ` Olivier Dion via
2022-06-14 19:53 ` [PATCH 1/2] gwl/workflows: Execute independent processes in parallel Olivier Dion
2022-06-14 19:53 ` Olivier Dion [this message]
2022-06-15 23:28 ` [PATCH 2/2] gwl/ui: Protect format to currnt-error-port with mutex Ricardo Wurmus
2022-06-15 23:27 ` [PATCH 1/2] gwl/workflows: Execute independent processes in parallel Ricardo Wurmus
2022-06-16 1:23 ` Olivier Dion via
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.guixwl.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220614195337.30570-2-olivier.dion@polymtl.ca \
--to=olivier.dion@polymtl.ca \
--cc=gwl-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).