Posted Dec 13, 2007 13:07 UTC (Thu) by davecb (subscriber, #1574)
Parent article: Simpler syslets
At least one experimental lisp had a "future"
function, which took a complete function call
and returned a function to call at some convenient
later time to get the results of the function.
In pseudo-c
void *later = future(function_to_run, (args_to_pass));
Future would start the function running
asynchronously with code to catch its
results.
The caller to future would eventually call "later"
and if the results were already there, would return
with them. If not, it would block until they
were available.
I found this elegant, and note that it separates
indirection and threadlet-ing.
--dave
Posted Dec 21, 2007 15:35 UTC (Fri) by ringerc (subscriber, #3071)
[Link]
That's rather similar to how Java-style threading is done in the case where the "master"
thread and the child task share no data. Presumably that's always the case in lisp, given its
functional design.
Sure, the Java approach is uglier and more verbose, but the principle remains practically the
same. You can use a callback or (with the TrollTech Qt approach) event in the event loop to
detect completion. Or you can just poll for completion by testing an instance variable of the
thread subclass.
http://java.sun.com/j2se/1.3/docs/api/java/lang/Thread.html
A similar approach can be used in C++ with Qt. It's really rather nice, and makes threading
quite sane for launching independent deferred calls that should produce a result "later".