unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* make-thread with lambda form instead of function symbol
@ 2017-04-16 16:05 Eric Abrahamsen
  2017-04-16 16:21 ` Noam Postavsky
  2017-04-17  1:12 ` Eric Abrahamsen
  0 siblings, 2 replies; 17+ messages in thread
From: Eric Abrahamsen @ 2017-04-16 16:05 UTC (permalink / raw)
  To: emacs-devel

Okay, one more thread question...

I'm trying to do something that seems like it would be a normal use
case: spawn a series of threads which call the same function using
different external processes. Practically what this means is that I want
to pass a function-plus-argument form to make-thread, not a function
symbol. Something like:

(let* ((results)
       (sources '(source1 source2))
       (threads
	(mapcar
	 (lambda (s)
	   (make-thread
	    (funcall
	     (lambda ()
	       (push (get-stuff-from-source s) results)))))
	 sources)))
  (mapc #'thread-join threads)
  results)

The (funcall (lambda () thing was the only way I could get anything but
nil out of the thread functions. I think I'm fooling myself, though: so
far as I can tell, `get-stuff-from-source' is fully evaluated before the
thread is made, and nothing at all happens during the #'thread-join
loop.

Is it possible to give make-thread anything but a function symbol? The
only other thing I could think of was looping over the sources and
making ad-hoc symbols:

(fset (make-symbol (format "%s-dummy-function" (source-name source)))
      (lambda () (push (get-stuff-from-source source) results)))

That seems ugly, but perhaps not that bad.

Thanks in advance,
Eric




^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2017-04-20  1:22 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-16 16:05 make-thread with lambda form instead of function symbol Eric Abrahamsen
2017-04-16 16:21 ` Noam Postavsky
2017-04-16 18:11   ` Eric Abrahamsen
2017-04-16 18:44     ` Noam Postavsky
2017-04-16 20:02       ` Eric Abrahamsen
2017-04-17  1:12 ` Eric Abrahamsen
2017-04-17  1:46   ` Noam Postavsky
2017-04-17  3:45     ` Eric Abrahamsen
2017-04-17  7:02       ` Eli Zaretskii
2017-04-17 16:54         ` Eric Abrahamsen
2017-04-17 17:18           ` Eric Abrahamsen
2017-04-17  6:51   ` Eli Zaretskii
2017-04-17  6:59   ` Andrew Cohen
2017-04-17 17:32     ` Eric Abrahamsen
2017-04-18  1:00       ` Andrew Cohen
2017-04-18  1:38         ` Eric Abrahamsen
2017-04-20  1:22     ` Eric Abrahamsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).