emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Return value of finished threads


From: Michael Albinus
Subject: Re: Return value of finished threads
Date: Sat, 21 Jul 2018 11:28:31 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Eli Zaretskii <address@hidden> writes:

>> (require 'thunk)
>> (defmacro thunk-delay-in-thread (&rest body)
>>   (declare (debug body))
>>   (let ((result-var (make-symbol "result")))
>>     `(let* ((,result-var nil)
>>             (thread (make-thread
>>                      (lambda ()
>>                        (setq ,result-var ,(macroexp-progn body))))))
>>        (thunk-delay (progn (thread-join thread) ,result-var)))))
>> 
>> (let ((thunks
>>        (mapcar
>>         (lambda (x) (thunk-delay-in-thread
>>                      (message "computing square of %d" x) (* x x)))
>>         (number-sequence 1 10))))
>>   ;; Run this thread first, just to make things more interesting.
>>   (thunk-force (nth 5 thunks))
>>   ;; Get all the values.
>>   (mapcar #'thunk-force thunks))
>
> This sounds gross to me, FWIW.

Yes. See my other mail for an implementation in threads.c.

Best regards, Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]