[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: no output from ice-9 `format' after `make-thread'
From: |
Marius Vollmer |
Subject: |
Re: no output from ice-9 `format' after `make-thread' |
Date: |
03 Nov 2002 01:00:51 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
Eric Hanchrow <address@hidden> writes:
> Invoke the snippet with `guile -s snippet.scm'. Note the total lack
> of output.
The process exits before it can produce any output. "guile -s" exits
as soon as the main thread exits. (The builtin simple-format is
probably fast enough to produce output anyway.)
Try this:
(use-modules (ice-9 threads))
(use-modules (ice-9 format))
(define safe-format
(let ((m (make-mutex)))
(lambda args
(with-mutex m
(apply format args)))))
(let ((ts (map (lambda (sym)
(make-thread
(lambda ()
(sleep (random 4))
(safe-format #t "Hey you: ~A~%" sym))))
(list 'bob 'sam 'huey 'luey 'duey))))
(for-each join-thread ts))
It uses join-thread to wait for the threads to finish.
Note also that (ice-9 format) is not thread safe... (which I'm going
to fix soonish (when nothing preempts me)).
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405